liujie
2026-09-20 25999c575dd42b4715e49d3fe57e73c2c3204ccb
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.estate.expert.admin.domain.common.response;
 
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.domain.Page;
 
import java.util.List;
 
@ApiModel("分页响应")
@Data
public class PageResp<T> {
 
    @ApiModelProperty("总页数")
    private int totalPages;
 
    @ApiModelProperty("总记录数")
    private long totalElements;
 
    @ApiModelProperty("每页大小")
    private int pageSize;
 
    @ApiModelProperty("当前页码, 从0开始")
    private int number;
 
    @ApiModelProperty("数据列表")
    private List<T> list;
 
    public PageResp(Page<?> page, List<T> list) {
        this.totalPages = page.getTotalPages();
        this.totalElements = page.getTotalElements();
        this.pageSize = page.getSize();
        this.number = page.getNumber();
        this.list = list;
    }
 
    public PageResp(Page<T> page) {
        this.totalPages = page.getTotalPages();
        this.totalElements = page.getTotalElements();
        this.pageSize = page.getSize();
        this.number = page.getNumber();
        this.list = page.getContent();
    }
 
    public PageResp(List<T> list) {
        this.list = list;
        this.totalPages = 1;
        this.totalElements = list.size();
        this.pageSize = list.size();
        this.number = 0;
    }
 
    // of
    public static <T> PageResp<T> of(Page<?> page, List<T> list) {
        return new PageResp<>(page, list);
    }
 
    // of
    public static <T> PageResp<T> of(Page<T> page) {
        return new PageResp<>(page);
    }
 
    // of
    public static <T> PageResp<T> of(List<T> list) {
        return new PageResp<>(list);
    }
 
 
    // empty
    public static <T> PageResp<T> empty() {
        return new PageResp<>(Page.empty());
    }
}