确保你已经在SpringBoot中集成MyBatis,并能正常使用。我的环境已经集成了通用Mapper
说集成分页插件,不如说是介绍如何集成一个plugin。MyBatis提供了拦截器接口,我们可以实现自己的拦截器,将其作为一个plugin装入到SqlSessionFactory中。
这里用的分页插件是PageHelper
Github项目地址: https://github.com/pagehelper/pagehelper-spring-boot
导包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
springboot低版本的话,也需要用低版本。
基本不需要什么配置,在表的实体类中,需要加两个属性
@Transient
private Integer page = 1;
@Transient
private Integer rows = 1;
这个注解
![]()
这样就能够使用了,你也可以不要默认值。
注意点
一定要确认你的mybatis版本,之前我用了1.0.0的版本,没有任何效果,改成最新的1.2.0才有用。这里是mybatis版本是
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.2.0</version> </dependency>
1万+

被折叠的 条评论
为什么被折叠?



