pagehelper 会对查询的第一个 list 进行包装,里面包含了分页信息,但是在查询的时候,如果查询的是多个 list,那么 pagehelper 就会获取不到 total 信息,导致分页信息不准确。我这里使用的一个临时解决方案,是最后手动把第一个 list 包含的分页信息取出来,然后再手动设置到最后的 list 中,这样就可以获取到 total 信息了。
pagehelper 代码
12345678
public PageSerializable(List<? extends T> list) { this.list = (List<T>) list; if(list instanceof Page){ this.total = ((Page<?>)list).getTotal(); } else { this.total = list.size(); }}
将分页信息取出来
123456
// 第一个 list 包含分页信息。List<Senior> seniors = seniorService.selectAllUser(name, phone);Page<FormUserVo> formUserVos = new Page<>();formUserVos.addAll(formUserVos);// 提取出第一个 list 的分页信息并设置分页信息。formUserVos.setTotal(new PageInfo(seniors).getTotal());