依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-to-slf4j</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
</dependency>
实体类:
@Data
public class PageDTO {
.......
private int pageSize;
private int pageNum;
}
controller:
@ApiOperation(value = "分页查询", notes = "分页查询")
@GetMapping("/queryPage" )
public R<PageInfo<BVO>> queryPage(DTO dto) {
PageInfo<BVO> data = bService.queryPage(dto);
return R.ok(data);
}
service 实现类:
@Override
public PageInfo<BVO> queryPage(DTO dto) {
PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
List<BVO> data = bMapper.queryPageByCondition(dto);
Long count = busNetsimMapper.queryCount(dto);
PageInfo<BusNetsimVO> pageInfo = new PageInfo<>();
pageInfo.setList(data);
pageInfo.setTotal(count);
pageInfo.setPageSize(dto.getPageSize());
pageInfo.setPageNum(dto.getPageNum());
return pageInfo;
}