Body content in JSP:
<Tableclass= "Table Table-border table-bordered table-bg table-hover table-sort"> <thead> <TRclass= "Text-c"> <thwidth= "a">Id</th> <thwidth= "+">Type</th> <th>Content</th> <thwidth= "17%">User name</th> <thwidth= "+">Client IP</th> <thwidth= "+">Time</th> <!--<th width= > Operation </th> - </TR> </thead> </Table>
JS content:
$ ('. Table-sort '). DataTable ({"bprocessing": false,//whether to display the wait prompt "Bserverside" when fetching data: true,//This is used to Indicates that the data is "Bpaginate" via the server: TRUE,//whether to show paging "Sajaxsource": "${cxtpath}/globallog/getlist",//This is the requested address "Fnserverdata": retrievedata,//processing function for data "aocolumns": [{"Mdata": "ID"}, {"Mdata": "Type"}, {"Mdata": "Info"}, {"MDat A ":" UserName "}, {" Mdata ":" IP "}, {" Mdata ":" Time "} ]//corresponding to each column in the table}); function Retrievedata (ssource111,aodata111, fnCallback111) {$.ajax ({url:ssource111,//This is the request address corresponds to Saja XSource data: {"Aodata": Json.stringify (aoData111)},//This is to pass some basic data of the DataTable to the background, such as the starting position, the number of rows per page type: ' Post ', DataType: ' json ', Async:false, success:function (result) { fnCallback111 (result);//Pass the returned data to this method, the DataTable will automatically bind the data}, Error:function (msg) { } }); }
Java code:
1@RequestMapping (value = "/getlist")2 @ResponseBody3 Publicstring GetList (@RequestParam string aodata) {4Jsonarray jsonarray=(Jsonarray) jsonarray.parse (aodata);5 6String Secho =NULL;7 intIdisplaystart = 0;//Start Index8 intIdisplaylength = 10;//number of lines displayed per page9 Ten for(inti = 0; I < jsonarray.size (); i++) { OneJsonobject obj =(jsonobject) jsonarray.get (i); A if(Obj.get ("name"). Equals ("Secho")) -Secho = Obj.get ("Value"). toString (); - the if(Obj.get ("name"). Equals ("Idisplaystart")) -Idisplaystart =integer.parseint (Obj.get ("value")). toString ()); - - if(Obj.get ("name"). Equals ("Idisplaylength")) +Idisplaylength = Integer.parseint (Obj.get ("value")). toString ()); - } + A atJsonobject getobj =NewJsonobject (); -Getobj.put ("Secho", Secho);//DataTable must be in front of the -Getobj.put ("Itotalrecords", Globallogservice.getcount ());//The actual number of rows, the method that invokes the total number of records in the query -Getobj.put ("Itotaldisplayrecords", Globallogservice.getcount ());//The number of rows displayed, which is the same as the one written above - -Getobj.put ("Aadata", Globallogservice.getlist (Idisplaystart, idisplaylength));//To load data into Aadata,to return in JSON format in returnjsonobject.tojsonstring (getobj); -}
:
Spring Next DataTable Server paging