mybatis-plus + PageHelper集成分页

看了很多文章都没说清楚怎么集成mybatis-plus + PageHelper,搞了挺久的不是报错就是缺少包,后面解决了特此记录一下。
先说配置pom和applocation.yml

mybatis + pagehelper
pom文件:

<!--pagehelper分页插件 -->
<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.2.5</version>
</dependency>

application.yml

pagehelper:
  auto-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  page-size-zero: true
  params: count=countSql

mybatis-plus + pagehelper:
pom文件

<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.2.3</version>
   <!-- 要把关于mybatis的依赖去除掉 不然会报错 -->
   <exclusions>
       <exclusion>
           <groupId>org.mybatis</groupId>
           <artifactId>mybatis</artifactId>
       </exclusion>
       <exclusion>
           <groupId>org.mybatis</groupId>
           <artifactId>mybatis-spring</artifactId>
       </exclusion>
   </exclusions>
</dependency>
<!-- Mybatis-plus -->
<dependency>
   <groupId>com.baomidou</groupId>
   <artifactId>mybatis-plus-boot-starter</artifactId>
   <version>3.1.0</version>
</dependency>

application.yml

pagehelper:
  auto-dialect: mysql
  reasonable: true
  support-methods-arguments: true
  page-size-zero: true
  params: count=countSql

代码使用:

PageHelper.startPage(int pageNum, int pageSize, QueryWrapper wrapper);
PageInfo pageInfo = new PageInfo(mapper.selectList(wrapper);
System.out.print(pageInfo.getList());
System.out.print(pageInfo.getTotal());

主要就在于【pagehelper-spring-boot-starter】依赖里面有mybatis的依赖,所以如果mybatis-plus集成这个依赖的话就会因为引入了mybatis-plus又引入了mybatis报错。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值