如何在spring框架中开发jquery-jtable

时间:2016-07-08 06:33:54

标签: spring spring-mvc

我使用spring Framework MVC开发了一个示例jquery-jtable

但价格不会出现在表格中。

enter image description here

添加了使用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">&quot;/studentList.do&quot;</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">&quot;jt값 : &quot;</span> <span style="color: #333333">+</span>jtStartIndex<span style="color: #333333">+</span><span style="background-color: #fff0f0">&quot;/&quot;</span><span style="color: #333333">+</span>jtPageSize<span style="color: #333333">+</span><span style="background-color: #fff0f0">&quot;/&quot;</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">&lt;</span>HomeValueObject<span style="color: #333333">&gt;</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">&quot;OK&quot;</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">&quot;ERROR&quot;</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">&lt;</span>%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;
    pageEncoding=&quot;UTF-8&quot;%&gt;

<span style="color: #557799">&lt;!DOCTYPE html&gt;</span>
<span style="color: #007700">&lt;html&gt;</span>
<span style="color: #007700">&lt;head&gt;</span>
<span style="color: #007700">&lt;meta</span> <span style="color: #0000CC">charset=</span><span style="background-color: #fff0f0">&quot;UTF-8&quot;</span><span style="color: #007700">&gt;</span>
<span style="color: #007700">&lt;title&gt;</span>Insert title here<span style="color: #007700">&lt;/title&gt;</span>
	<span style="color: #007700">&lt;script </span><span style="color: #0000CC">src=</span><span style="background-color: #fff0f0">&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js&quot;</span><span style="color: #007700">&gt;&lt;/script&gt;</span>
	<span style="color: #007700">&lt;link</span> <span style="color: #0000CC">rel=</span><span style="background-color: #fff0f0">&quot;stylesheet&quot;</span> <span style="color: #0000CC">href=</span><span style="background-color: #fff0f0">&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css&quot;</span><span style="color: #007700">&gt;</span>
	<span style="color: #007700">&lt;script </span><span style="color: #0000CC">src=</span><span style="background-color: #fff0f0">&quot;https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js&quot;</span><span style="color: #007700">&gt;&lt;/script&gt;</span>
	<span style="color: #888888">&lt;!-- Include one of jTable styles. --&gt;</span>
	<span style="color: #007700">&lt;link</span> <span style="color: #0000CC">href=</span><span style="background-color: #fff0f0">&quot;/resources/jtable/themes/metro/blue/jtable.min.css&quot;</span> <span style="color: #0000CC">rel=</span><span style="background-color: #fff0f0">&quot;stylesheet&quot;</span> <span style="color: #0000CC">type=</span><span style="background-color: #fff0f0">&quot;text/css&quot;</span> <span style="color: #007700">/&gt;</span>
	<span style="color: #888888">&lt;!-- Include jTable script file. --&gt;</span>
	<span style="color: #007700">&lt;script </span><span style="color: #0000CC">src=</span><span style="background-color: #fff0f0">&quot;/resources/jtable/jquery.jtable.min.js&quot;</span> <span style="color: #0000CC">type=</span><span style="background-color: #fff0f0">&quot;text/javascript&quot;</span><span style="color: #007700">&gt;&lt;/script&gt;</span>
	
	<span style="color: #007700">&lt;script </span><span style="color: #0000CC">type=</span><span style="background-color: #fff0f0">&quot;text/javascript&quot;</span><span style="color: #007700">&gt;</span>
    $(<span style="color: #007020">document</span>).ready(<span style="color: #008800; font-weight: bold">function</span> () { 
        $(<span style="background-color: #fff0f0">&#39;#StudentTableContainer&#39;</span>).jtable({
            title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;The Student List&#39;</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">&#39;Name ASC&#39;</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">&#39;/studentList.do&#39;</span>,
                deleteAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;/deleteStudent.do&#39;</span>,
                updateAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;/updateStudent.do&#39;</span>,
                createAction<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;/insertStudent.do&#39;</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">&#39;Name&#39;</span>,
                    width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;23%&#39;</span>,
                },
                EmailAddress<span style="color: #333333">:</span> {
                    title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Email address&#39;</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">&#39;User Password&#39;</span>,
                    type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;password&#39;</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">&#39;Gender&#39;</span>,
                    width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;13%&#39;</span>,
                    options<span style="color: #333333">:</span> { <span style="background-color: #fff0f0">&#39;M&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Male&#39;</span>, <span style="background-color: #fff0f0">&#39;F&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Female&#39;</span> }
                },
                CityId<span style="color: #333333">:</span> {
                    title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;City&#39;</span>,
                    width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;12%&#39;</span>,
                    options<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;/getCityOptions.do&#39;</span>
                },
                BirthDate<span style="color: #333333">:</span> {
                    title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Birth date&#39;</span>,
                    width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;15%&#39;</span>,
                    type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;date&#39;</span>,
                    displayFormat<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;yy-mm-dd&#39;</span>
                },
                Education<span style="color: #333333">:</span> {
                    title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Education&#39;</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">&#39;radiobutton&#39;</span>,
                    options<span style="color: #333333">:</span> { <span style="background-color: #fff0f0">&#39;1&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Vietnam national university, Ha Noi&#39;</span>, 
                               <span style="background-color: #fff0f0">&#39;2&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Ha Noi university&#39;</span>, 
                               <span style="background-color: #fff0f0">&#39;3&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Thang Long university&#39;</span> }
                },
                About<span style="color: #333333">:</span> {
                    title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;About this person&#39;</span>,
                    type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;textarea&#39;</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">&#39;Status&#39;</span>,
                    width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;12%&#39;</span>,
                    type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;checkbox&#39;</span>,
                    values<span style="color: #333333">:</span> { <span style="background-color: #fff0f0">&#39;false&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Passive&#39;</span>, <span style="background-color: #fff0f0">&#39;true&#39;</span><span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Active&#39;</span> },
                    defaultValue<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;true&#39;</span>
                },
                RecordDate<span style="color: #333333">:</span> {
                    title<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;Record date&#39;</span>,
                    width<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;15%&#39;</span>,
                    type<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;date&#39;</span>,
                    displayFormat<span style="color: #333333">:</span> <span style="background-color: #fff0f0">&#39;dd.mm.yy&#39;</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">&#39;#StudentTableContainer&#39;</span>).jtable(<span style="background-color: #fff0f0">&#39;load&#39;</span>);
    });
	<span style="color: #007700">&lt;/script&gt;</span>
<span style="color: #007700">&lt;/head&gt;</span>
<span style="color: #007700">&lt;body&gt;</span>		
	<span style="color: #007700">&lt;div</span> <span style="color: #0000CC">id=</span><span style="background-color: #fff0f0">&quot;StudentTableContainer&quot;</span><span style="color: #007700">&gt;&lt;/div&gt;</span>
<span style="color: #007700">&lt;/body&gt;</span>
<span style="color: #007700">&lt;/html&gt;</span>
</pre></div>

这是JSP代码。

我参考并正在建立此链接。 http://www.codeproject.com/Articles/1091086/jTable-with-Java-Spring-MVC-Integration

它与MySQL DB互锁并且学生价格被带来但结论无法安装显示在桌面上。

我该怎么办?

0 个答案:

没有答案