ResultPage.java
1.1 KB
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
package com.aigeo.common;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* 分页结果封装类
*/
@Data
@Schema(description = "分页结果封装类")
public class ResultPage<T> {
@Schema(description = "当前页码")
private int pageNumber;
@Schema(description = "每页记录数")
private int pageSize;
@Schema(description = "总记录数")
private long total;
@Schema(description = "总页数")
private int totalPages;
@Schema(description = "当前页数据")
private List<T> items;
public ResultPage() {
}
public ResultPage(int pageNumber, int pageSize, long total, List<T> items) {
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.total = total;
this.items = items;
this.totalPages = (int) Math.ceil((double) total / pageSize);
}
/**
* 创建分页结果
*/
public static <T> ResultPage<T> of(int pageNumber, int pageSize, long total, List<T> items) {
return new ResultPage<>(pageNumber, pageSize, total, items);
}
}