liujie
2026-01-20 b506a0a10cdf3ac34cfdae2b82da4dae49b41567
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
74
75
76
77
78
package com.estate.expert.admin.domain.common.response;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
 
 
import java.util.List;
 
/**
 * mybatis plus 分页响应
 * @param <T>
 */
@ApiModel("分页响应")
@Data
public class PageRespMp<T> {
 
    @ApiModelProperty("总页数")
    private int totalPages;
 
    @ApiModelProperty("总记录数")
    private long totalElements;
 
    @ApiModelProperty("每页大小")
    private int pageSize;
 
    @ApiModelProperty("当前页码, 从0开始")
    private int number;
 
    @ApiModelProperty("数据列表")
    private List<T> list;
 
    public PageRespMp(Page<?> page, List<T> list) {
        this.totalPages = (int) page.getPages();
        this.totalElements = page.getTotal();
        this.pageSize = (int) page.getSize();
        this.number = (int) page.getCurrent();
        this.list = list;
    }
 
    public PageRespMp(Page<T> page) {
        this.totalPages = (int) page.getPages();
        this.totalElements = page.getTotal();
        this.pageSize = (int) page.getSize();
        this.number = (int) page.getCurrent();
        this.list = page.getRecords();
    }
 
    public PageRespMp(List<T> list) {
        this.list = list;
        this.totalPages = 1;
        this.totalElements = list.size();
        this.pageSize = list.size();
        this.number = 0;
    }
 
    // of
    public static <T> PageRespMp<T> of(Page<?> page, List<T> list) {
        return new PageRespMp<>(page, list);
    }
 
    // of
    public static <T> PageRespMp<T> of(Page<T> page) {
        return new PageRespMp<>(page);
    }
 
    // of
    public static <T> PageRespMp<T> of(List<T> list) {
        return new PageRespMp<>(list);
    }
 
 
    // empty
    public static <T> PageRespMp<T> empty() {
        return new PageRespMp<>(new Page<>());
    }
}