Mybatis-Spring icon indicating copy to clipboard operation
Mybatis-Spring copied to clipboard

springBoot1.5.9+pagehelper5.0每页显示数量居然等于总记录数?!

Open stwen opened this issue 7 years ago • 1 comments

springBoot1.5.9+mybatis+oracle+pagehelper5.0

  • 每页显示数量居然等于总记录数?! 下面这个是我的方法:
    public ServiceResponse queryPageByParams(String groupName,String userName, int currentPage, int pageSize) throws Exception{
        PageHelper.startPage(currentPage, pageSize);//如1,5
        List<CheckGroupVo> checkGroupVoList = checkGroupUserDao.queryPageByParams(groupName,userName);//查出来的结果是13条
        if(checkGroupVoList == null){
            return ServiceResponse.createByResponseCode(ResponseCode.NOT_EXIST);
        }
        PageInfo info = new PageInfo(checkGroupVoList);
        System.out.println(info.getList());//经过上面PageInfo后,pageSize居然等于总记录数13!!!
        return ServiceResponse.createByResponseCodeData(ResponseCode.GET_SUCCESS, new PageInfo(checkGroupVoList));
    }

然后调试进入new PageInfo时,居然进入下面的 else if (list instanceof Collection)条件,把查询出来的总记录数赋值给每页显示数量 this.pageSize = list.size();!!!! 什么情况?

public PageInfo(List<T> list, int navigatePages) {
        super(list);
        if (list instanceof Page) {
            Page page = (Page) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();

            this.pages = page.getPages();
            this.size = page.size();
            //由于结果是>startRow的,所以实际的需要+1
            if (this.size == 0) {
                this.startRow = 0;
                this.endRow = 0;
            } else {
                this.startRow = page.getStartRow() + 1;
                //计算实际的endRow(最后一页的时候特殊)
                this.endRow = this.startRow - 1 + this.size;
            }
        }else if (list instanceof Collection) {
            this.pageNum = 1;
            this.pageSize = list.size();

            this.pages = this.pageSize > 0 ? 1 : 0;
            this.size = list.size();
            this.startRow = 0;
            this.endRow = list.size() > 0 ? list.size() - 1 : 0;
        }
        if (list instanceof Collection) {
            this.navigatePages = navigatePages;
            //计算导航页
            calcNavigatepageNums();
            //计算前后页,第一页,最后一页
            calcPage();
            //判断页面边界
            judgePageBoudary();
        }
    }

stwen avatar May 16 '18 08:05 stwen

说明你的代码没有真正进行分页,你可以看 SQL 日志。

最有可能的情况就是分页插件没配置对,没起作用。

abel533 avatar May 17 '18 03:05 abel533