分页查询controller写法
public PageResult findByList(@RequestBody UserDTO userDTO) { // 分页 IPage<User> page = new Page(UserDTO.getPageNumber(), UserDTO.getPageSize()); // 条件构造器 QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("user_name", userDTO.getUserName); // 查询符合条件的内容 IPage<User> pageResult = service.page(page, queryWrapper); // 获取符合条件的List集合 List<User> records = pageResult.getRecords(); System.out.println("查询结果 = " + records); // 返回结果 return new PageResult(new Long(pageResult.getTotal()).intValue(), pageResult.getRecords()); }
返回结果集写法
可根据需求自定义
/** * 分页处理 */ @ApiModel("分页响应类") public class PageResult<T> { @ApiModelProperty(value ="响应代码") private int code; @ApiModelProperty(value ="提示信息") private String msg; @ApiModelProperty(value ="总记录数") private int count; @ApiModelProperty(value ="查询到的结果集") private List<T> data; /** * 默认构造方法 */ public PageResult() { } public PageResult(int total, List<T> rows) { this.count = total; this.data = rows; this.code = 200; this.msg = Constant.ResponseMsg.OPERATE_SUCCESS; } public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public List<T> getData() { return data; } public void setData(List<T> data) { this.data = data; } }