引入jar包
之前引入的是
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
只有这一个包
在这种情况下需要在项目的入口类application.java加入额外配置
// 解决springboot 与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");
pageHelper.setProperties(properties);
return pageHelper;
}
引入适配Spring Boot包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
发现这里会多出两个包,不需要加任何配置
使用
@ApiOperation(value = "列表查询", httpMethod = "GET", produces = "application/json")
@RequestMapping(value = "/onSearch", method = RequestMethod.GET)
public PageInfo<AlmRecord> getByParams(@ApiParam(value = "用于查询的条件") @RequestParam(required = false) Map<String, String> params) {
try {
logger.info("AlmRecordController getByParams id=" + params);
PageHelper.startPage(Integer.parseInt(params.get("offset")), Integer.parseInt(params.get("limit")));
List<AlmRecord> selectById = service.selectByParams(params);
PageInfo<AlmRecord> appsPageInfo = new PageInfo<>(selectByParams);
return selectById;
} catch (Exception e) {
logger.error("AlmRecordController getByParams error:", e);
return null;
}
}