-
Notifications
You must be signed in to change notification settings - Fork 0
/
PageInation.java
116 lines (88 loc) · 2.91 KB
/
PageInation.java
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
/**
* 通用分页器
*
* @author liyebing created on 15/9/10.
* @version $Id$
*/
public class PageInation<T> implements Serializable {
private static final long serialVersionUID = 4773269869603036013L;
//默认每页大小
private static final int DEFAULT_SIZE = 20;
//存放当前页中的数据
private List<T> data;
//每页大小
private int pageSize;
//记录总数
private int totalCount;
//当前页的数据
private int currentPage;
//总页数
private int totalPage;
public PageInation() {
this(0, DEFAULT_SIZE, 0, Collections.EMPTY_LIST);
}
public static <T> PageInation<T> create(){
return new PageInation<T>();
}
public static <T> PageInation<T> create(int currentPage, int pageSize, int totalCount){
return new PageInation<T>(currentPage,pageSize,totalCount);
}
public static <T> PageInation<T> create(int currentPage, int pageSize, int totalCount,List<T> data){
return new PageInation<T>(currentPage,pageSize,totalCount,data);
}
public PageInation(int currentPage, int pageSize, int totalCount){
this.currentPage = currentPage;
this.totalCount=totalCount;
this.pageSize=pageSize;
totalPage = totalCount % pageSize == 0 ? (totalCount / pageSize) : (totalCount / pageSize + 1);
}
public PageInation(int currentPage, int pageSize, int totalCount, List<T> data) {
this.currentPage = currentPage;
this.data = data;
this.totalCount=totalCount;
this.pageSize=pageSize;
//totalPage = (totalCount + size - 1) / size;
totalPage = totalCount % pageSize == 0 ? (totalCount / pageSize) : (totalCount / pageSize + 1);
}
public PageInation(int currentPage, int totalCount, List<T> data) {
this.currentPage = currentPage;
this.data = data;
this.totalCount=totalCount;
this.pageSize=DEFAULT_SIZE;
//totalPage = (totalCount + size - 1) / size;
totalPage = totalCount % DEFAULT_SIZE == 0 ? (totalCount / DEFAULT_SIZE) : (totalCount / DEFAULT_SIZE + 1);
}
public int getCurrentPage() {
return currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public void setData(List<T> data) {
this.data = data;
}
public List<T> getData() {
return data;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getOffset() {
return (currentPage-1)*pageSize;
}
}