两种都很方便,说明一下使用方法
请求对象实体里需要定义page 和rows ,integer类型
@Override public PageInfo<RuRuleEntity> getRuleList(RuRuleReq request) { PageHelper.startPage(request.getPage(),request.getRows()); List<RuRuleEntity> list = baseMapper.selectAllRule(request); PageInfo<RuRuleEntity> pageInfo = new PageInfo<>(list); return pageInfo; }
第二种写法也需要定义page和rows
@Override public IPage<OperationContrastResponse> getOperationContrastList(ContrastRequest request) { if (request.getPage() == null || request.getRows() == null) { throw new BusinessException(ResultCodeEnum.ERR_0x1001.getCode(), "page或rows不可为空");} IPage<OperationContrastResponse> ipage = new Page<>(request.getPage(),request.getRows()); IPage<OperationContrastResponse> responseIPage = baseMapper.getOperationContrastList(ipage,request); return responseIPage; }
直接用mabtis写法查询的话,要改用专属的分页方法 IPage<RuRuleEntity> iPage=new Page<>(request.getPage(),request.getRows()); IPage<RuRuleEntity> list=baseMapper.selectPage(iPage,queryWrapper);
如果过个对象都需要写page和rows可以写个通用对象进行继承
public class PageHelper implements Serializable { private static final long serialVersionUID = 5696856545105043089L; @ApiModelProperty(value = "当前页码") private Integer page; @ApiModelProperty(value = "每页加载数量") private Integer rows; /** * 表的列名 */ @ApiModelProperty(value = "排序") private String column; /** * asc | desc */ @ApiModelProperty(value = "排序方向") private String dir; }
本文作者:Weee
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!