前台jsp展示部分,通过将needUrl传入到后台查询List和Total
$(function(){
initialize("task.do?submitflag=toList");
})
function initialize(needUrl){
window['g'] =
$("#maingrid").ligerGrid({
checkbox: true,
columns: [
{ display: '预警代码', name: 'alarmCode', hide:1}, //hide:1标识该列隐藏不显示
{ display: '机构名称', name: 'orgName', align:'left' ,width: 100 }
], dataAction: 'server',pageSize:10,
url: needUrl,
height: '100%',
toolbar: { items: [
{ text: '确定', click: addExample , icon: 'add' },
{ line: true }
]
});
}
后台通过将needUrl查询得到的List 和总数total转换为JSON数据写出
public static void writeOut(List<?> list,int total,HttpServletResponse response){
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
try {
PrintWriter out = response.getWriter();
Map<String,Object> mm = new HashMap<String,Object>();
mm.put("Rows", list);
mm.put("Total", total);
out.print(JSONObject.fromObject(mm));
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
}