使用SpringBoot创建工程,在配置好通用Mapper和PageHelper后,发现使用PageHelper.startPage()后,查询结果一直是表中的所有数据,PageHelper.startPage()失效。
SpringBoot项目中必须使用该包pagehelper-spring-boot-starter
pom.xml
<!-- 通用mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>
<!-- PageHelper分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
在配置dialect: mysql,一直报错。通过网上资料发现使用全类名可以解决该问题。但是在使用PageHelper.startPage()方法时,分页并不会生效。
application.yml中配置通用mapper和PageHelper
#通用mapper配置
mapper:
identity: MYSQL
#PageHelper插件配置 该配置对PageHelper不起作用。使用config包中的PageHelperConfig方式可以起作用。
pagehelper:
#原来的配置

本文介绍了在SpringBoot项目中,整合通用Mapper和PageHelper遇到的分页失效问题。当使用PageHelper.startPage()时,查询结果始终为全部数据。解决方案包括使用特定的pagehelper-spring-boot-starter包,配置dialect为全类名,并调整PageHelper配置。在某些情况下,可能需要删除application.yml中的PageHelper配置以使分页生效。
最低0.47元/天 解锁文章
3250





