EmployeeController
/**
* 员工分页查询
*
* @param employeePageQueryDTO
* @return
*/
@GetMapping("/page")
@ApiOperation("员工分页查询")
public Result<PageResult> page(EmployeePageQueryDTO employeePageQueryDTO) {
log.info("员工分页查询,参数为{}", employeePageQueryDTO);
PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO);
return Result.success(pageResult);
}
EmployeeService
/**
* 分页查询方法
* @param employeePageQueryDTO
* @return
*/
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
EmployeeMapper
/**
* 分页查询
*
* @param employeePageQueryDTO
* @return
*/
public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
//分页查询软插件PageHelper
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
//因为用了PageHelper插件所以返回值是固定的 Page<Employee>page
Page<Employee> page = employeeMapper.pageQuery(employeePageQueryDTO);
//把page封装成pageresult对象
//PageResult包含total ,result
long total = page.getTotal();
List<Employee> result = page.getResult();
return new PageResult(total, result);
}
分页查询的插件
分页查询软插件PageHelper