做mybatis-demo2时遇到pagehelper分页失效情况,记录一下:

1.首先,最关键的问题是依赖以及版本

因为**里面有好几个都包含pagehelper,例如:

1
2
3
4
5
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.1</version>
</dependency>

但是这个是不会生效的!

应该导这个依赖:

1
2
3
4
5
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>

并且,version是有要求的,1.2.x的我没成功,换成1.4.1成功了,可能这个版本号跟springboot的版本号是有关系的。

2.其次就是网上讨论最多的,PageHelper.startPage只会对接下来一句紧挨着的查询语句分页,如果再下面还有则会失效。

1.png

两句顺序不能调换。

2.png 3.png

这里全局定义了每页3条数据。