当前位置: 编程技术>WEB前端
jquery datatable后台封装数据示例代码
来源: 互联网 发布时间:2014-08-25
本文导语: 1.数据转换类 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.setiTotal...
1.数据转换类
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帮助类
public class BaseController { protected JSONResponse successed(Object obj) { JSONResponse ret = new JSONResponse(); ret.setSuccessed(true); ret.setReturnObject(obj); return ret; } }
3.实现类
public JSONResponse searchList(HttpServletRequest request , HttpServletResponse response ,String sEcho) throws Exception { //convertToMap定义于父类,将参数数组中的所有元素加入一个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 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,重新设值使用 queryParams.put("AO_DATA", data); queryParams.put("COUNT", iCount); return queryParams; }
注意存放的数组对象的属性必须与前端页面显示的列保持一样的个数