There are many examples of jquery DataTable online, but the combination of SPRINGMVC is very rare, and it took 2 days to figure this out and now record it as a learning note.
1. Import the required files
(1) Jquery.dataTables.css
(2) Jquery.js
(3) Jquery.dataTables.js
2.datatable.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" Utf-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
3. Background Request Address Tabledemoajax@RequestMapping ("Tabledemoajax") @ResponseBodypublic string Tabledemoajax (@RequestParam string aodata) {Jsonarray Jsonarray = Jsonarray.fromobject (Aodata); String Secho = Null;int Idisplaystart = 0; Starting index int idisplaylength = 0; Number of rows displayed per page for (int i = 0; i < jsonarray.size (); i++) {Jsonobject obj = (jsonobject) jsonarray.get (i); if (Obj.get ("name" ). Equals ("Secho")) Secho = Obj.get ("value"). ToString (), if (Obj.get ("name"). Equals ("Idisplaystart")) Idisplaystart = Obj.getint ("value"), if (Obj.get ("name"). Equals ("Idisplaylength")) Idisplaylength = Obj.getint ("value");} Generates 20 test data list<string[]> LST = new arraylist<string[]> (); for (int i = 0; i <; i++) {string[] D = {"Co 1_data "+ I," col2_data "+ I};lst.add (d);} Jsonobject getobj = new Jsonobject () getobj.put ("Secho", secho);//Do not know the value of what use, you know, please inform the getobj.put ("Itotalrecords", Lst.size ());//The actual number of rows Getobj.put ("Itotaldisplayrecords", Lst.size ());//The number of rows displayed, which is as written above Getobj.put ("Aadata", Lst.sublist (Idisplaystart,idisplaystart + IDISPLaylength));//To return the return getobj.tostring () in JSON format;}
4.
Springmvc + jquery DataTable + ajax for dynamic paging queries