今天在调用一个查询列表的接口时,分页总数老是查的不正确:
当pageSize选择10时,总数只有10条
当pageSize选择20时,总数只有15条
实际上总数为15条实在正确的,然后取看代码:
@Overridepublic AjaxResult projectCountDetail(Long id, StorageAccount account, String firstCategory, String secondCategory, String toolName, String modelName, Integer pageNum, Integer pageSize) {PageHelper.startPage(pageNum, pageSize);List<ProjectStatisticsVo> list = this.storageProjectInfoManagementMapper.projectCountDetail(id, account.getAccount(), firstCategory, secondCategory, toolName, modelName);for (ProjectStatisticsVo projectStatisticsVo : list) {//判断工器具是否有标识Integer flag = storageRecipientRecordMapper.getToolFlag(projectStatisticsVo.getId());//无标识falseprojectStatisticsVo.setFlag(flag == 1 ? false : true);//归还数量int backCount = storageProjectInfoManagementMapper.getBackCount(id, projectStatisticsVo.getId(), account.getAccount());projectStatisticsVo.setReturnCount(backCount);projectStatisticsVo.setNoReturnCount(projectStatisticsVo.getRecipientCount() - projectStatisticsVo.getReturnCount());projectStatisticsVo.setProjectId(id);}List<ProjectStatisticsVo> list = list.stream().filter(projectStatisticsVo -> projectStatisticsVo.getId() != null).collect(Collectors.toList());PageInfo<ProjectStatisticsVo> pageInfo = new PageInfo<>(list);return AjaxResult.success(pageInfo);}
问题排查:
PageInfo后面取得时二次操作的list,导致分页失败
解决:
简单改成这样就OK