Pagehelper 不分页几种情况的解决方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012620150/article/details/84988367

第一种情况: mybatis 引入版本不对

    <dependency>
       <groupId>org.mybatis.spring.boot</groupId>
       <artifactId>mybatis-spring-boot-starter</artifactId>
       <version>1.0.0</version>
    </dependency>

请不要使用1.0.0版本,因为还不支持拦截器插件,可用1.0.0之后的版本

第二种情况:pagehelper 引入不对,正确的应该引入:

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.5</version>
</dependency>

第三种情况:设置数据的方法写在分页前面(代码顺序不对)

 Page<Object> page = PageHelper.startPage(pageNo, pageSize, true);
  result.setList(hotWordService.getHotWordsIndustryList());

第四种情况:设置数据里的mapper的多次查询,Page只会以第一次查出的结果来分页:(貌似不对,但确定能分页了,搞不懂)

 Page<Object> page = PageHelper.startPage(pageNo, pageSize, true);
  result.setList(hotWordService.getHotWordsIndustryList());

getHotWordsIndustryList()方法:
 @Override
    public List<CallRecordSimpleVO> getCompletedCallRecordByCallTaskId(CallTaskSimpleVO callTaskSimpleVO) {
   	 Long userId = callTaskMapper.getUserIdById(callTaskSimpleVO.getCallTaskId());
        if (userId == null || !Objects.equals(userId, ThreadCacheMgr.getUserId())) {
            throw new CallTaskException(CallTaskExceptionCode.CALL_TASK_NOT_AUTHORITY);
        }
        return callRecordMapper.getCallRecordByCallTaskId(callTaskSimpleVO);
    }

方法里有callTaskMapper和callRecordMapper的查询,分页针对第一个mapper的查询来分,所以分页数据是 callTaskMapper.getUserIdById 的查询结果。应该改成:

 Long userId = callTaskMapper.getUserIdById(callTaskSimpleVO.getCallTaskId());
        if (userId == null || !Objects.equals(userId, ThreadCacheMgr.getUserId())) {
            throw new CallTaskException(CallTaskExceptionCode.CALL_TASK_NOT_AUTHORITY);
        }
 Page<Object> page = PageHelper.startPage(pageNo, pageSize, true);
  result.setList(hotWordService.getHotWordsIndustryList());

getHotWordsIndustryList()方法:
 @Override
  public List<CallRecordSimpleVO> getCompletedCallRecordByCallTaskId(CallTaskSimpleVO callTaskSimpleVO) {
        return callRecordMapper.getCallRecordByCallTaskId(callTaskSimpleVO);
    }

猜你喜欢

转载自blog.csdn.net/u012620150/article/details/84988367