1. 客户端分页
1) js页面
sidePagination : "client", // 设置在哪里进行分页,可选值为"client" 或者 "server"
responseHandler: function(data){
return data.rows;
},
queryParams : function(params) {
return {
limit: params.limit,
offset:params.offset,
name:$('#searchName').val()
};
},
2) controller页面
@ResponseBody
@GetMapping("/list")
public PageUtils opentList(@RequestParam Map<String, Object> params) {
// Query query = new Query(params);
List<VirtualMachineDTO> VMList = vCenterService.list(params);
int total = VMList.size();
PageUtils pageUtils = new PageUtils(VMList, total);
return pageUtils;
}
2. 服务端分页
1) js页面
sidePagination : "server",
queryParams : function(params) {
return {
limit: params.limit,
offset:params.offset,
name:$('#searchName').val()
// username:$('#searchName').val()
};
},
2) controller页面
@ResponseBody
@GetMapping("/listFromDB")
public PageUtils listFromDB(@RequestParam Map<String, Object> params) {
Query query = new Query(params);
List<VirtualMachineDTO> VMList = vCenterService.listFromDB(query);
int total = vCenterService.count(query);
PageUtils pageUtils = new PageUtils(VMList, total);
return pageUtils;
}
注意:分页查询时,需将前台传过来的limit参数转为整数类型
public Query(Map<String, Object> params) {
this.putAll(params);
// 分页参数
this.offset = Integer.parseInt(params.get("offset").toString());
this.limit = Integer.parseInt(params.get("limit").toString());
this.put("offset", offset);
this.put("page", offset / limit + 1);
this.put("limit", limit);
}