jquery的DataTable的java后台返回的数据结构
解决方法:
Map<String,Object> context = getRootMap();
context.put("draw","");
context.put("recordsTotal",20);
context.put("recordsFiltered",10);
List<Map<String,String>> datas=new ArrayList<Map<String,String>>();
Map jsonObject = new HashMap();
jsonObject.put("0", "第一列的值");
jsonObject.put("1", "第二列的值");
jsonObject.put("2", "第三列的值");
jsonObject.put("3", "第四列的值");
jsonObject.put("4", "第五列的值");
jsonObject.put("5", "第六列的值");
jsonObject.put("6", "第七列的值");
datas.add(jsonObject);
context.put("data",datas);
try {
StringBuffer result = new StringBuffer();
//设置页面不缓存
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-javascript;charset=UTF-8");
PrintWriter out= null;
out = response.getWriter();
out.print(JSONUtil.toJSONString(context));
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}