PageHelper.startPage(pageNum, pageSize);分页总数不正确,避坑!

今天在调用一个查询列表的接口时,分页总数老是查的不正确:

当pageSize选择10时,总数只有10条

当pageSize选择20时,总数只有15条

 

实际上总数为15条实在正确的,然后取看代码:

    @Override
    public AjaxResult projectCountDetail(Long id, StorageAccount account, String firstCategory, String secondCategory, String toolName, String modelName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List list = this.storageProjectInfoManagementMapper.projectCountDetail(id, account.getAccount(), firstCategory, secondCategory, toolName, modelName);
        for (ProjectStatisticsVo projectStatisticsVo : list) {
            //判断工器具是否有标识
            Integer flag = storageRecipientRecordMapper.getToolFlag(projectStatisticsVo.getId());
            //无标识false
            projectStatisticsVo.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 list = list.stream()
                .filter(projectStatisticsVo -> projectStatisticsVo.getId() != null)
                .collect(Collectors.toList());
        PageInfo pageInfo = new PageInfo<>(list);
        return AjaxResult.success(pageInfo);
    }

问题排查:

PageInfo后面取得时二次操作的list,导致分页失败

PageHelper.startPage(pageNum, pageSize);分页总数不正确,避坑!_第1张图片

解决:

简单改成这样就OK

PageHelper.startPage(pageNum, pageSize);分页总数不正确,避坑!_第2张图片 

 

你可能感兴趣的:(mybatis,java)