Page.java
1.81 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
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
package com.brframework.commonweb.json;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* Created by xu on 2017/1/5.
* 返回分页数据
*/
@Data
@ApiModel
public class Page<T> {
/**
* 每页显示条数
*/
@ApiModelProperty(value = "每页最大显示条数", required = true, example = "12")
private int pageSize;
/**
* 当前页 1开始
*/
@ApiModelProperty(value = "页索引(1开始)", required = true, example = "1")
private int pageIndex;
/**
* 总页数
*/
@ApiModelProperty(value = "总页数", required = true, example = "10")
private int pageTotal;
/**
* 总数据条数
*/
@ApiModelProperty(value = "总条数", required = true, example = "103")
private long total;
/**
* 分页数据上
*/
private List<T> list = new ArrayList<>();
public Page(int pageIndex, int pageSize, long total) {
//页码转换到前端,由1开始
this.pageIndex = pageIndex + 1;
this.pageSize = pageSize;
this.total = total;
this.pageTotal = (int) ( total % pageSize == 0 ? total / pageSize : total / pageSize + 1 );
}
/**
* 获取分页开始的索引
*
* @return
*/
@JSONField(serialize = false)
public int getStartIndex() {
return (pageIndex - 1) * pageSize;
}
/**
* 获取分页结束的索引
*
* @return
*/
@JSONField(serialize = false)
public int getEndIndex() {
return pageIndex * pageSize;
}
public static Page copyPage(Page copyer) {
return new Page(copyer.getPageIndex(), copyer.getPageSize(), copyer.getTotal());
}
}