我使用spring Framework MVC开发了一个示例jquery-jtable
。
但价格不会出现在表格中。
添加了使用JSON的代码。
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #555555; font-weight: bold">@Controller</span>
<span style="color: #008800; font-weight: bold">public</span> <span style="color: #008800; font-weight: bold">class</span> <span style="color: #BB0066; font-weight: bold">DemoController</span>
<span style="color: #333333">{</span>
<span style="color: #555555; font-weight: bold">@Resource</span>
<span style="color: #008800; font-weight: bold">private</span> HomeService homeService<span style="color: #333333">;</span>
<span style="color: #555555; font-weight: bold">@RequestMapping</span><span style="color: #333333">(</span>value <span style="color: #333333">=</span> <span style="background-color: #fff0f0">"/studentList.do"</span><span style="color: #333333">,</span> method <span style="color: #333333">=</span> RequestMethod<span style="color: #333333">.</span><span style="color: #0000CC">POST</span><span style="color: #333333">)</span>
<span style="color: #555555; font-weight: bold">@ResponseBody</span>
<span style="color: #008800; font-weight: bold">public</span> JsonResult <span style="color: #0066BB; font-weight: bold">StudentList</span><span style="color: #333333">(</span>Integer jtStartIndex<span style="color: #333333">,</span> Integer jtPageSize<span style="color: #333333">,</span> String jtSorting<span style="color: #333333">)</span>
<span style="color: #333333">{</span>
<span style="color: #008800; font-weight: bold">try</span><span style="color: #333333">{</span>
<span style="color: #888888">//Get data from database</span>
System<span style="color: #333333">.</span><span style="color: #0000CC">out</span><span style="color: #333333">.</span><span style="color: #0000CC">println</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">"jt값 : "</span> <span style="color: #333333">+</span>jtStartIndex<span style="color: #333333">+</span><span style="background-color: #fff0f0">"/"</span><span style="color: #333333">+</span>jtPageSize<span style="color: #333333">+</span><span style="background-color: #fff0f0">"/"</span><span style="color: #333333">+</span>jtSorting<span style="color: #333333">);</span>
<span style="color: #333399; font-weight: bold">int</span> studentCount <span style="color: #333333">=</span> homeService<span style="color: #333333">.</span><span style="color: #0000CC">selectStudentCount</span><span style="color: #333333">();</span>
HomeValueObject listVo <span style="color: #333333">=</span> <span style="color: #008800; font-weight: bold">new</span> HomeValueObject<span style="color: #333333">();</span>
jtStartIndex <span style="color: #333333">=</span> <span style="color: #0000DD; font-weight: bold">10</span><span style="color: #333333">*</span>jtStartIndex<span style="color: #333333">;</span>
listVo<span style="color: #333333">.</span><span style="color: #0000CC">setJtStartIndex</span><span style="color: #333333">(</span>jtStartIndex<span style="color: #333333">);</span>
listVo<span style="color: #333333">.</span><span style="color: #0000CC">setJtPageSize</span><span style="color: #333333">(</span>jtPageSize<span style="color: #333333">);</span>
listVo<span style="color: #333333">.</span><span style="color: #0000CC">setJtSorting</span><span style="color: #333333">(</span>jtSorting<span style="color: #333333">);</span>
List<span style="color: #333333"><</span>HomeValueObject<span style="color: #333333">></span> studentList <span style="color: #333333">=</span> homeService<span style="color: #333333">.</span><span style="color: #0000CC">selectStudentList</span><span style="color: #333333">(</span>listVo<span style="color: #333333">);</span>
<span style="color: #888888">//Return result to jTable</span>
<span style="color: #008800; font-weight: bold">return</span> <span style="color: #008800; font-weight: bold">new</span> <span style="color: #0066BB; font-weight: bold">Json</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">"OK"</span><span style="color: #333333">,</span>studentList<span style="color: #333333">,</span>studentCount<span style="color: #333333">);</span>
<span style="color: #333333">}</span>
<span style="color: #008800; font-weight: bold">catch</span><span style="color: #333333">(</span>Exception e<span style="color: #333333">){</span>
<span style="color: #008800; font-weight: bold">return</span> <span style="color: #008800; font-weight: bold">new</span> <span style="color: #0066BB; font-weight: bold">Json</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">"ERROR"</span><span style="color: #333333">,</span>e<span style="color: #333333">.</span><span style="color: #0000CC">getMessage</span><span style="color: #333333">());</span>
<span style="color: #333333">}</span>
<span style="color: #333333">}</span>
</pre></div>
这是控制器代码。
和
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #FF0000; background-color: #FFAAAA"><</span>%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<span style="color: #557799"><!DOCTYPE html></span>
<span style="color: #007700"><html></span>
<span style="color: #007700"><head></span>
<span style="color: #007700"><meta</span> <span style="color: #0000CC">charset=</span><span style="background-color: #fff0f0">"UTF-8"</span><span style="color: #007700">></span>
<span style="color: #007700"><title></span>Insert title here<span style="color: #007700"></title></span>
<span style="color: #007700"><script </span><span style="color: #0000CC">src=</span><span style="background-color: #fff0f0">"https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"</span><span style="color: #007700">></script></span>
<span style="color: #007700"><link</span> <span style="color: #0000CC">rel=</span><span style="background-color: #fff0f0">"stylesheet"</span> <span style="color: #0000CC">href=</span><span style="background-color: #fff0f0">"https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"</span><span style="color: #007700">></span>
<span style="color: #007700"><script </span><span style="color: #0000CC">src=</span><span style="background-color: #fff0f0">"https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"</span><span style="color: #007700">></script></span>
<span style="color: #888888"><!-- Include one of jTable styles. --></span>
<span style="color: #007700"><link</span> <span style="color: #0000CC">href=</span><span style="background-color: #fff0f0">"/resources/jtable/themes/metro/blue/jtable.min.css"</span> <span style="color: #0000CC">rel=</span><span style="background-color: #fff0f0">"stylesheet"</span> <span style="color: #0000CC">type=</span><span style="background-color: #fff0f0">"text/css"</span> <span style="color: #007700">/></span>
<span style="color: #888888"><!-- Include jTable script file. --></span>
<span style="color: #007700"><script </span><span style="color: #0000CC">src=</span><span style="background-color: #fff0f0">"/resources/jtable/jquery.jtable.min.js"</span> <span style="color: #0000CC">type=</span><span style="background-color: #fff0f0">"text/javascript"</span><span style="color: #007700">></script></span>
<span style="color: #007700"><script </span><span style="color: #0000CC">type=</span><span style="background-color: #fff0f0">"text/javascript"</span><span style="color: #007700">></span>
$(<span style="color: #007020">document</span>).ready(<span style="color: #008800; font-weight: bold">function</span> () {
$(<span style="background-color: #fff0f0">'#StudentTableContainer'</span>).jtable({
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'The Student List'</span>,
paging<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">true</span>, <span style="color: #888888">//Enable paging</span>
pageSize<span style="color: #333333">:</span> <span style="color: #0000DD; font-weight: bold">10</span>, <span style="color: #888888">//Set page size (default: 10)</span>
sorting<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">true</span>, <span style="color: #888888">//Enable sorting</span>
defaultSorting<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Name ASC'</span>, <span style="color: #888888">//Set default sorting</span>
actions<span style="color: #333333">:</span> {
listAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'/studentList.do'</span>,
deleteAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'/deleteStudent.do'</span>,
updateAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'/updateStudent.do'</span>,
createAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'/insertStudent.do'</span>
},
fields<span style="color: #333333">:</span> {
StudentId<span style="color: #333333">:</span> {
key<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">true</span>,
create<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>,
edit<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>,
list<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>
},
Name<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Name'</span>,
width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'23%'</span>,
},
EmailAddress<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Email address'</span>,
list<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>
},
Password<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'User Password'</span>,
type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'password'</span>,
list<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>
},
Gender<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Gender'</span>,
width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'13%'</span>,
options<span style="color: #333333">:</span> { <span style="background-color: #fff0f0">'M'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Male'</span>, <span style="background-color: #fff0f0">'F'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Female'</span> }
},
CityId<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'City'</span>,
width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'12%'</span>,
options<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'/getCityOptions.do'</span>
},
BirthDate<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Birth date'</span>,
width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'15%'</span>,
type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'date'</span>,
displayFormat<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'yy-mm-dd'</span>
},
Education<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Education'</span>,
list<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>,
type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'radiobutton'</span>,
options<span style="color: #333333">:</span> { <span style="background-color: #fff0f0">'1'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Vietnam national university, Ha Noi'</span>,
<span style="background-color: #fff0f0">'2'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Ha Noi university'</span>,
<span style="background-color: #fff0f0">'3'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Thang Long university'</span> }
},
About<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'About this person'</span>,
type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'textarea'</span>,
list<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>
},
IsActive<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Status'</span>,
width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'12%'</span>,
type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'checkbox'</span>,
values<span style="color: #333333">:</span> { <span style="background-color: #fff0f0">'false'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Passive'</span>, <span style="background-color: #fff0f0">'true'</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Active'</span> },
defaultValue<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'true'</span>
},
RecordDate<span style="color: #333333">:</span> {
title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'Record date'</span>,
width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'15%'</span>,
type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'date'</span>,
displayFormat<span style="color: #333333">:</span> <span style="background-color: #fff0f0">'dd.mm.yy'</span>,
create<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>,
edit<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span>,
sorting<span style="color: #333333">:</span> <span style="color: #008800; font-weight: bold">false</span> <span style="color: #888888">//This column is not sortable!</span>
}
}
});
<span style="color: #888888">//Load student list from server</span>
$(<span style="background-color: #fff0f0">'#StudentTableContainer'</span>).jtable(<span style="background-color: #fff0f0">'load'</span>);
});
<span style="color: #007700"></script></span>
<span style="color: #007700"></head></span>
<span style="color: #007700"><body></span>
<span style="color: #007700"><div</span> <span style="color: #0000CC">id=</span><span style="background-color: #fff0f0">"StudentTableContainer"</span><span style="color: #007700">></div></span>
<span style="color: #007700"></body></span>
<span style="color: #007700"></html></span>
</pre></div>
这是JSP代码。
我参考并正在建立此链接。 http://www.codeproject.com/Articles/1091086/jTable-with-Java-Spring-MVC-Integration
它与MySQL DB互锁并且学生价格被带来但结论无法安装显示在桌面上。
我该怎么办?