springboot mybatis 分页pagehelper

 


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);

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值