java成长之路

pagehelper分页控件的pageSize设置

2017-07-25  本文已影响2317人  sweetMemories

工程使用了springboot构建,故在build.gradle添加依赖

compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.1.1')

实际添加的jar包(部分)

Gradle: com.github.jsqlparser:jsqlparser:0.9.5
Gradle: com.github.pagehelper:pagehelper:5.0.1

官网关于pageSize的说明

params: In support of startPage(Object params) method, The parameter is added to configure the parameter mapping for the value from the object based on the attribute name, you can configure pageNum,pageSize,count,pageSizeZero,reasonable, Default value is pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero

jar包实际代码

//RowBounds参数offset作为PageNum使用 - 默认不使用
protected boolean offsetAsPageNum = false;
//RowBounds是否进行count查询 - 默认不查询
protected boolean rowBoundsWithCount = false;
//当设置为true的时候,如果pagesize设置为0(或RowBounds的limit=0),就不执行分页,返回全部结果
protected boolean pageSizeZero = false;
//分页合理化
protected boolean reasonable = false;
//是否支持接口参数来传递分页参数,默认false
protected boolean supportMethodsArguments = false;
//默认count(0)
protected String countColumn = "0";

解决方法

配置参数

#项目配置
root:
  #分页大小
  pageSize: 10

建RootPropeties类读取该参数

@Component
@ConfigurationProperties(prefix = "root")
public class RootPropeties {

    private Integer pageSize;

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}

调用语句

PageInfo<CouponInfo> page = PageHelper.startPage(pageNo, rootPropeties.getPageSize()).doSelectPageInfo(() -> couponInfoDao.getCouponInfo());
上一篇 下一篇

猜你喜欢

热点阅读