工程使用了springboot構(gòu)建,故在build.gradle添加依賴(lài)
compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.1.1')
實(shí)際添加的jar包(部分)
Gradle: com.github.jsqlparser:jsqlparser:0.9.5
Gradle: com.github.pagehelper:pagehelper:5.0.1
官網(wǎng)關(guān)于pageSize的說(shuō)明
- 可以在params中設(shè)置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包實(shí)際代碼
- 在實(shí)際代碼com.github.pagehelper.page.PageParams中卻無(wú)pageSize參數(shù),故pageSize不生效
- 下列為存在的參數(shù)
//RowBounds參數(shù)offset作為PageNum使用 - 默認(rèn)不使用
protected boolean offsetAsPageNum = false;
//RowBounds是否進(jìn)行count查詢(xún) - 默認(rèn)不查詢(xún)
protected boolean rowBoundsWithCount = false;
//當(dāng)設(shè)置為true的時(shí)候,如果pagesize設(shè)置為0(或RowBounds的limit=0)蚂维,就不執(zhí)行分頁(yè)陶耍,返回全部結(jié)果
protected boolean pageSizeZero = false;
//分頁(yè)合理化
protected boolean reasonable = false;
//是否支持接口參數(shù)來(lái)傳遞分頁(yè)參數(shù)赏陵,默認(rèn)false
protected boolean supportMethodsArguments = false;
//默認(rèn)count(0)
protected String countColumn = "0";
解決方法
配置參數(shù)
- 在application.yml設(shè)置pageSize參數(shù)
#項(xiàng)目配置
root:
#分頁(yè)大小
pageSize: 10
建RootPropeties類(lèi)讀取該參數(shù)
@Component
@ConfigurationProperties(prefix = "root")
public class RootPropeties {
private Integer pageSize;
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
調(diào)用語(yǔ)句
- 使用了jdk8 lambda語(yǔ)法
- rootPropeties.getPageSize()即頁(yè)面大小參數(shù)
PageInfo<CouponInfo> page = PageHelper.startPage(pageNo, rootPropeties.getPageSize()).doSelectPageInfo(() -> couponInfoDao.getCouponInfo());