Jquerydatatable sample code for encapsulating data in the background _ jquery

Source: Internet
Author: User
This article mainly introduces the sample code of jquerydatatable Data encapsulation in the background. For more information, see 1. Data Conversion

public class DataTableReturnObject { private int iTotalRecords; private int iTotalDisplayRecords; private String sEcho; private String[][] aaData; public DataTableReturnObject(int totalRecords, int totalDisplayRecords, String echo, String[][] d) { this.setiTotalRecords(totalRecords); this.setiTotalDisplayRecords(totalDisplayRecords); this.setsEcho(echo); this.setAaData(d); } public void setiTotalRecords(int iTotalRecords) { this.iTotalRecords = iTotalRecords; } public int getiTotalRecords() { return iTotalRecords; } public void setiTotalDisplayRecords(int iTotalDisplayRecords) { this.iTotalDisplayRecords = iTotalDisplayRecords; } public int getiTotalDisplayRecords() { return iTotalDisplayRecords; } public void setsEcho(String sEcho) { this.sEcho = sEcho; } public String getsEcho() { return sEcho; } public void setAaData(String[][] aaData) { this.aaData = aaData; } public String[][] getAaData() { return aaData; } }

2. Help class

public class BaseController { protected JSONResponse successed(Object obj) { JSONResponse ret = new JSONResponse(); ret.setSuccessed(true); ret.setReturnObject(obj); return ret; } }

3. Implementation class

Public JSONResponse searchList (HttpServletRequest request, HttpServletResponse response, String sEcho) throws Exception {// convertToMap is defined in the parent class and Adds all elements in the parameter array to a HashMap Map
 
  
ObjQueryMap = new HashMap
  
   
(); String jsondata = request. getParameter ("aoData"); JSONArray jsonarray = JSONArray. fromObject (jsondata); String strDisplayStart = ""; String strDisplayLength = ""; String [] arrayColumen = new String [new JSONUser (). toArray (). length]; int strSortId = 0; String strSort = ""; for (int I = 0; I
   
    
Params = new HashMap
    
     
(); Try {params = managerService. getUserList (parameter);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace ();} String count = (String) params. get ("COUNT"); // total String [] [] strData = (String [] []) params. get ("AO_DATA"); // return successed (new DataTableReturnObject (Integer. parseInt (count), Integer. parseInt (count), sEcho, strData ));}
    
   
  
 

4. Query Method

Public Map
 
  
GetUserList (Map
  
   
QueryParams) throws Exception {String iCount = Total number of records; // converts the query result to a two-dimensional array String [] [] data ={}; if (lstUser! = Null & lstUser. size ()> 0) {int record = lstUser. size (); data = new String [record] []; for (int I = 0; I <lstUser. size (); I ++) {User objUser = (User) lstUser. get (I); JSONUser jsonUser = new JSONUser (); BeanUtils. copyProperties (jsonUser, objUser); data [I] = jsonUser. toArray () ;}} queryParams. clear (); // map, reset the value to use queryParams. put ("AO_DATA", data); queryParams. put ("COUNT", iCount); return queryParams ;}
  
 

Note that the attributes of the stored array object must be the same as the number of columns displayed on the front-end page.

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.