jquery datatable服务端分页

2020-05-29 07:14:36易采站长站整理

String sSearch = null;
Integer iSortCol_0 = null;
String iSortCol = null;
String sSortDir_0 = null;
for (int i = 0; i < ja.size(); i++) {
if (ja.getJSONObject(i).getString("name").equals("sEcho"))
sEcho = ja.getJSONObject(i).getString("value");
else if (ja.getJSONObject(i).getString("name").equals("iColumns"))
iColumns = Integer.valueOf(ja.getJSONObject(i).getString("value"));
else if (ja.getJSONObject(i).getString("name").equals("iDisplayStart"))
iDisplayStart = Integer.valueOf(ja.getJSONObject(i).getString("value"));
else if (ja.getJSONObject(i).getString("name").equals("iDisplayLength"))
iDisplayLength = Integer.valueOf(ja.getJSONObject(i).getString("value"));
else if (ja.getJSONObject(i).getString("name").equals("sSearch"))
sSearch = ja.getJSONObject(i).getString("value");
else if (ja.getJSONObject(i).getString("name").equals("iSortCol_0"))
iSortCol_0 = Integer.valueOf(ja.getJSONObject(i).getString("value"));
else if (ja.getJSONObject(i).getString("name").equals("sSortDir_0"))
sSortDir_0 = ja.getJSONObject(i).getString("value");
else if (iColumns != null) {
for (int j = 0; j < iColumns; j++)
if (ja.getJSONObject(i).getString("name").equals("mDataProp_" + j))
mDataProp.add(ja.getJSONObject(i).getString("value"));
}
}
iSortCol = mDataProp.get(iSortCol_0);
System.out.println(sEcho);
System.out.println(iColumns);
System.out.println(iDisplayStart);
System.out.println(iDisplayLength);
System.out.println(sSearch);
System.out.println(iSortCol);
System.out.println(sSortDir_0);

// 从数据库获取数据
List<User> listUser = Service.getInstance().getAll();

// 数据封装并返回给客户端
DataTableJSONResponse dtjs = new DataTableJSONResponse(listUser);
JSONObject jsonObject = JSONObject.fromObject(dtjs);
response.getWriter().print(jsonObject.toString());
}

好的,加工完毕,这时我们跑一跑看看是不是打出我们要的参数,这里我就不贴出来了,你们自己跑了看,好的发现拿到了我们要的参数,那么接下来可以拼接我们的sql语句了,同时我们要对我们的DataTableJSONResponse进行一下小小的修改,因为这里对于返回的数据也是有参数要求的,那我们就把需要的参数放进去,代码如下:


public class DataTableJSONResponse {
Object sEcho;
Object iTotalRecords; //查询的记录数
Object iTotalDisplayRecords; //过滤后的记录数
Object aaData;

public DataTableJSONResponse() {
super();
}

public DataTableJSONResponse(Object aaData) {
super();
this.aaData = aaData;
}

public DataTableJSONResponse(Object sEcho, Object iTotalRecords, Object iTotalDisplayRecords, Object aaData) {
super();
this.sEcho = sEcho;
this.iTotalRecords = iTotalRecords;