看了很多文章都没说清楚怎么集成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报错。