mybtais 分页 pagehelper
官网:https://pagehelper.github.io
************************
导入jar包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
************************
参数配置
offsetAsPageNum:默认为false,对RowBounds有效,设为true时,将offset当成pageNum用
rowBoundsWithCount:默认为false,对RowBounds有效,设为true时,使用RowBounds分页会进行count查询
pageSizeZero:默认为false,设为true时,pageSize=0或者rowBounds.limit=0时,会查询出所有的数据
reasonable:默认为false,设为true时,pageNum<=0时会查询出第一页,pageNum>page(总页数),会查询最后一页
params:定义拦截的参数名称,
默认值:pageNum=pageNum;pageSize=pageSize;count=countSql;reasonable=reasonable;pageSizeZero=pageSizeZero
supportMethodsArguments:默认false,设为true时,会拦截mapper接口中params定义的参数
public interface CountryMapper {
List<Country> selectByPageNumSize( @Param("user") User user,
@Param("pageNum") int pageNum,
@Param("pageSize") int pageSize);
} //设为true时,会拦截自定义方法中的参数,需要自定义方法,不推荐使用
************************
配置建议
pagehelper:
offset-as-page-num: true
row-bounds-with-count: true
page-size-zero: true
reasonable: true
分页查询时可用通用mapper提供的方法进行分页查询
List<T> selectByRowBounds(T record, RowBounds rowBounds);
List<T> selectByExampleAndRowBounds(Object example, RowBounds rowBounds);
或者使用
PageHepler.startPage(offset,limit);
PageHelper.offsetPage(offset,limit);