通过List流操作和手动PageInfo分页解决,如下:
@Override
public ResponseResult getStudentScoreList(String search, Integer page, Integer pageSize, UserDetails userInfo) {
//查询班级下的所以学生
List<StudentScoreVO> scoreVOList = studentMapper.getStudentScoreStatus(search,userInfo.getId());
/**
*此处省略,中间对结果集合做了内容处理
**/
//计算总记录数
int total = scoreVOList.size();
//pageHelper无效,手动分页,流操作:sorted排序、skip跳记录和limit限制显示记录数
List<StudentScoreVO> collect = scoreVOList
.stream()
.sorted(Comparator.comparingInt(StudentScore::getGainPoint))
.skip((page - 1) * pageSize)
.limit(pageSize)
.collect(Collectors.toList());
//计算总页数
int pageSum = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
PageHelper.startPage(page, pageSize);
PageInfo<StudentScoreVO> scorePageInfo = new PageInfo<>(collect);
//总记录数
scorePageInfo.setTotal(total);
//总页数
scorePageInfo.setPages(pageSum);
//清除分页缓存
PageHelper.clearPage();
return ResponseResult.success(scorePageInfo);
}