[toc] ## 返回对象: ### 分页对象 ~~~ @Data @Builder @NoArgsConstructor @AllArgsConstructor public class PageResult<T> implements Serializable { private static final long serialVersionUID = -275582248840137389L; private Long count; private int code; private List<T> data; } ~~~ ### 普通对象 ~~~ @Data @NoArgsConstructor @AllArgsConstructor public class Result<T> implements Serializable { private static final long serialVersionUID = -4696008537295855861L; private T data; private Integer code; private String msg; public static <T> Result<T> succeed(String msg) { return succeedWith(null, CodeEnum.SUCCESS.getCode(), msg); } public static <T> Result<T> succeed(T model, String msg) { return succeedWith(model, CodeEnum.SUCCESS.getCode(), msg); } public static <T> Result<T> succeedWith(T data, Integer code, String msg) { return new Result<T>(data, code, msg); } public static <T> Result<T> failed(String msg) { return failedWith(null, CodeEnum.ERROR.getCode(), msg); } public static <T> Result<T> failed(T model, String msg) { return failedWith(model, CodeEnum.ERROR.getCode(), msg); } public static <T> Result<T> failedWith(T data, Integer code, String msg) { return new Result<T>(data, code, msg); } } ~~~ ## 如何分页 ~~~ /** * 分页的时候建议 */ @Transactional(propagation = Propagation.NOT_SUPPORTED) public PageResult<Demo> selectPage(PageRequest pageRequest) { PageHelper.startPage(pageRequest.getPageNum(), pageRequest.getPageSize()); List<Demo> demoList = demoMapper.selectList(null); PageInfo<Demo> pageInfo = new PageInfo<>(demoList); return PageUtils.getPageResult(pageInfo); } ~~~