zzw
2023-12-01 e023474fc9bcc726ed558a0623f1316dddc13152
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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();
            }
        }
    }
}