package com.zt.common.servlet; import com.zt.common.db.query.PageList; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; import java.util.List; @Data public class PageResult { /** * 编码:0表示成功,其他值表示失败 */ @ApiModelProperty(value = "编码:0表示成功,其他值表示失败") private int code = 0; @ApiModelProperty(value = "消息内容") private String msg = "success"; @ApiModelProperty(value = "响应数据") private PageData data; public static PageResult ok(List data) { PageResult result = new PageResult<>(); result.setData(new PageData<>(data)); return result; } @Data @ApiModel(value = "分页数据") public static class PageData implements Serializable { @ApiModelProperty(value = "总记录数") private int total; @ApiModelProperty(value = "列表数据") private List list; public PageData(List list) { this.list = list; if (list instanceof PageList) { this.total = (int) ((PageList) list).getTotal(); } else { this.total = list.size(); } } } }