package com.hxqc.pricemonitor.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.context.request.WebRequest;
public class DataTablePageUtil<T> {
private int draw; // 第几次请求
private int start = Constants.IDISPLAYSTART;// 起止位置
private int length = Constants.DISPLAYLENGTH; // 数据长度
private List<T> data;
private int recordsTotal; // 数据总记录数
private int recordsFiltered; // 过滤数
private Map<String, Object> condition = new HashMap<String, Object>(); // 查询条件
public DataTablePageUtil() {
}
@SuppressWarnings("unchecked")
public DataTablePageUtil(WebRequest request) {
if (StringUtils.isNotBlank(request.getParameter("aoData"))) {
JSONArray jsonarray = JSONArray.fromObject(request
.getParameter("aoData"));
for (int i = 0; i < jsonarray.size(); i++) {
JSONObject obj = (JSONObject) jsonarray.get(i);
if (obj.get("name").equals("sEcho"))
this.setDraw(obj.getInt("value"));
if (obj.get("name").equals("iDisplayStart"))
this.setStart(obj.getInt("value"));
if (obj.get("name").equals("iDisplayLength"))
this.setLength(obj.getInt("value"));
}
}
if (StringUtils.isNotBlank(request.getParameter("searchData"))) {
JSONObject searchData = JSONObject.fromObject(request
.getParameter("searchData"));
this.setCondition(searchData);
}
}
public int getDraw() {
return draw;
}
public void setDraw(int draw) {
this.draw = draw;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public List<T> getData() {
return data;
}
public void setData(List<T> data) {
this.data = data;
}
public Map<String, Object> getCondition() {
return condition;
}
public void setCondition(Map<String, Object> condition) {
this.condition = condition;
}
public int getRecordsTotal() {
return recordsTotal;
}
public void setRecordsTotal(int recordsTotal) {
this.recordsTotal = recordsTotal;
}
public int getRecordsFiltered() {
return recordsFiltered;
}
public void setRecordsFiltered(int recordsFiltered) {
this.recordsFiltered = recordsFiltered;
}
}