springboot中pageHelper插件 list设置不进去 为null

分页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 会以第一个查询分页
原文地址:https://www.cnblogs.com/yr1126/p/10383471.html