| 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<T> { | 
|     /** | 
|      * 编码:0表示成功,其他值表示失败 | 
|      */ | 
|     @ApiModelProperty(value = "编码:0表示成功,其他值表示失败") | 
|     private int code = 0; | 
|   | 
|     @ApiModelProperty(value = "消息内容") | 
|     private String msg = "success"; | 
|   | 
|     @ApiModelProperty(value = "响应数据") | 
|     private PageData<T> data; | 
|   | 
|     public static <T> PageResult<T> ok(List<T> data) { | 
|         PageResult<T> result = new PageResult<>(); | 
|         result.setData(new PageData<>(data)); | 
|         return result; | 
|     } | 
|   | 
|     @Data | 
|     @ApiModel(value = "分页数据") | 
|     public static class PageData<T> implements Serializable { | 
|   | 
|         @ApiModelProperty(value = "总记录数") | 
|         private int total; | 
|   | 
|         @ApiModelProperty(value = "列表数据") | 
|         private List<T> list; | 
|   | 
|         public PageData(List<T> list) { | 
|             this.list = list; | 
|             if (list instanceof PageList) { | 
|                 this.total = (int) ((PageList) list).getTotal(); | 
|             } else { | 
|                 this.total = list.size(); | 
|             } | 
|         } | 
|     } | 
| } |