1.导入jar包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelperboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
2.启动类添加配置文件
// 解决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;
}
3.测试类
@PostMapping("listpage")
public @ResponseBody
ResponsePageData<CipherEntity> listpage(
@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, String appName, String type
) {
ResponsePageData<CipherEntity> ret = new ResponsePageData<>();
ret.setCode("200");
CipherEntity entity = new CipherEntity();
entity.setAppName(appName);
entity.setType(type);
Page<CipherEntity> data = PageHelper.startPage(page, limit);
List<CipherEntity> acts = iCipherService.listpage(null, entity);
if (acts.size() == 0) {
ret.setMessage("没有查询到数据");
} else {
ret.setTotalCount((int) data.getTotal());
ret.setList(acts);
ret.setMessage("SUCCESS");
}
return ret;
}
|