方法一:使用PageHelper插件
1.首先在pom.xml中引入依赖。
<!-- pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.13</version>
</dependency>
2.使用方法:
PageHelper.startPage(pageNum,pageSize);
List<Map<String, Object>> data = groupTypeService.findList(map);
PageInfo<Map<String, Object>> info = new PageInfo<>(data);
3.application.properties文件中
#pagehelper分页插件配置 以下属性不加也可以实现分页功能
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
注意:如果报错,估计就是版本的原因,就去加版本试试,、
当前最新版本
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
报错实例
Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelpe
Requested bean is currently in creation: Is there an unresolvable circular rHelpe