启动类Application.java中配置PageHelper实例
@Bean public PageHelper pageHelper() { PageHelper pageHelper = new PageHelper(); Properties properties = new Properties(); properties.setProperty("offsetAsPageNum", "true"); properties.setProperty("rowBoundsWithCount", "true"); properties.setProperty("reasonable", "true"); properties.setProperty("dialect", "mysql"); //配置mysql数据库的方言 pageHelper.setProperties(properties); return pageHelper; }
pom依赖如下:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.2.0</version> </dependency>
分页代码如下:
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; PageHelper.startPage(pageNo, pageSize); PageInfo<Card> page = new PageInfo<>(cardMapper.query(record)); return ResultUtils.buildPageSucc(page.getList(), (int)page.getTotal());
通过查看以上代码配置都没有问题,通过网上查询后,发现缺少pom配置pagehelper-spring-boot-starter
解决方法:
增加如下pom配置
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.12</version> </dependency>