1.pom.xml 引入maven依赖,这里引入的是pagehelper starter依赖,并不是单纯的pagehelper库:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
2.application.yml配置文件:
#pagehelper分页插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
3.service中调用:
PageHelper.startPage(pageNum, pageSize);
List<Permission> list = permissionMapper.selectByExample(testExample);
使用比较简单,但不能实现分页查询。我遇到的问题是这样的:springboot parent版本2.0.0.RELEASE,pagehelper版本是4.1.4可以用:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.4</version>
</dependency>
新构建的项目:boot parent版本是2.1.4.RELEASE,引入原来pagehelper4.1.4 不能实现分页。经过反复试验,将pagehelper版本更改为 pagehelper-spring-boot-starter :1.2.5后可以实现分页,问题解决。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
本文主要讲述在Spring Boot项目中使用PageHelper进行分页查询时遇到的问题。原项目springboot parent版本2.0.0.RELEASE,pagehelper4.1.4可用;新构建项目boot parent版本2.1.4.RELEASE,该版本无法分页。经试验,将其改为pagehelper - spring - boot - starter:1.2.5后可实现分页。

5587

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



