1. 程式人生 > >springboot中pageHelper插件 list設置不進去 為null

springboot中pageHelper插件 list設置不進去 為null

lis ebo 設置 解決 camel pip agen default pin

分頁pageHelper中list放不進去值 為null,可能的解決方案如下:

1.技術分享圖片

註意代碼順序,PageHelper.startPage(pageNumber,pageSize)要放在查詢List的前面

代碼如下:

PageHelper.startPage(pageNumber,pageSize);

List<User> list=userMapper.selectAll(map);

2.PageBean的泛型不加

比如:PageBean info=new PageBean(list);

@RequestMapping(value = "/getList7",method = RequestMethod.GET)
@ResponseBody
public PageBean getList7(@ApiParam(name ="pageNumber",value = "頁碼",defaultValue = "1",required = true)int pageNumber,
@ApiParam(name ="pageSize",value = "條數",defaultValue = "10",required = true)int pageSize,
@ApiParam(name ="sortName",value = "排序名稱")String sortName,
@ApiParam(name ="sortOrder",value = "排序方式")String sortOrder,
HttpServletRequest request) {
Map map=request.getParameterMap();
if(StringUtils.isNotBlank(sortName) && StringUtils.isNotBlank(sortOrder)){
PageHelper.orderBy(CommonUtil.camel2Underline(sortName)+" "+sortOrder);
}else{
PageHelper.orderBy("id desc");
}
PageHelper.startPage(pageNumber,pageSize);
List<User> list=userMapper.selectAll(map);
PageBean info=new PageBean(list);
return info;

3.pageInfo中的值再設置一遍,往pageBean中強制設置值

PageHelper.startPage(pageNumber,pageSize);
List<User> list=userMapper.selectAll(param);
PageBean<User> info = new PageBean<>(list);
info.setTotal(new PageInfo(list).getTotal());
info.setPageNumber(pageNumber);
info.setPageSize(pageSize);
info.setRows(list);
info.setPages(new PageInfo(list).getPages());
info.setSize(new PageInfo(list).getSize());
return info;

4.註意分頁中不能有多個mapper查詢List 會以第一個查詢分頁

springboot中pageHelper插件 list設置不進去 為null