当前使用版本(必须填写清楚,否则不予处理)

3.0.7.1

该问题是怎么引起的?(最新版上已修复的会直接close掉)

使用分页器com.baomidou.mybatisplus.extension.plugins.pagination.Page进行分页查询,如果current是0,则会返回第一页数据。

期望:current为0,则报异常,或打印警告/错误日志

重现步骤

使用简单分页模型:com.baomidou.mybatisplus.extension.plugins.pagination.Page时,创建对象时,传current = 0,调用任意一个Mapper的com.baomidou.mybatisplus.core.mapper.BaseMapper#selectPage方法,会返回第一页的数据。

原因是:

    public Page(long current, long size, long total, boolean isSearchCount) {
        if (current > 1) {
            this.current = current;
        }
        this.size = size;
        this.total = total;
        this.isSearchCount = isSearchCount;
    }

构造方法仅当current > 1的时候,才会把入参赋值给this.currrent,否则为默认的1

报错信息

备注

在Spring Batch、Elastic Search API等组件中,往往会认为第一页是从0开始,如果不仔细查看,很容易导致数据库的第一页数据重复写入。本着快速失败的原则,如果入参是不合法的参数则应该快速返回失败,要求使用者修改。

也可以参考此项目:https://github.com/pagehelper/Mybatis-PageHelper,提供一个配置项reasonable,默认情况下currnet < 1或 current > maxPage时,不返回数据,设置reasonable=true,则会分别返回第一页和最后一页数据。

Comment From: miemieYaho

自行继承 Ipage 实现逻辑并使用