Springmvc + jquery DataTable + ajax for dynamic paging queries

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.