PageObject.java
2.56 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.bsth.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* 该类为公共分页类,用于查询数据时用
* @author
* @version
*/
public class PageObject<T>
{
/**
* 首页
*/
private final int firstPage = Common.FIRST_PAGE;
/**
* 每页的数据量
*/
private int pageData = Common.PAGE_DATA;
/**
* 当前页
*/
private int curPage = Common.FIRST_PAGE;
/**
* 下一页
*/
private int nextPage;
/**
* 上一页
*/
private int prePage;
/**
* 最后一页
*/
private int endPage;
/**
* 总页数
*/
private int totalPage;
/**
* 总数据量
*/
private int totalData;
/**
* 保存的数据
*/
@SuppressWarnings("unchecked")
private List<T> dataList = Collections.EMPTY_LIST;
/**
* 页码
*/
private List<Integer> pageList = new ArrayList<Integer>();
public PageObject() {
}
public PageObject(int totalData,int curPage){
this.totalData = totalData;
this.curPage = curPage;
pageValue();
}
public PageObject(int totalData,int curPage,int pageData){
this.totalData = totalData;
this.curPage = curPage;
this.pageData = pageData;
pageValue();
}
private void pageValue(){
pageList.add(Common.FIRST_PAGE);
if (0 != totalData)
{
//得到总页数以及最后一页
this.endPage = this.totalPage = totalData % pageData == 0 ? totalData / pageData : totalData / pageData + 1;
for (int i = 2;i <= endPage;i ++)
{
pageList.add(i);
}
//判断当前页的页码是否合法
this.curPage = curPage > totalPage ? totalPage : curPage;
//得到前一页的页码
this.prePage = curPage < 2 ? firstPage : curPage - 1;
//得到后一页的页码
this.nextPage = curPage == totalPage ? totalPage : curPage + 1;
}
}
public int getFirstPage() {
return firstPage;
}
public int getPageData() {
return pageData;
}
public int getCurPage() {
return curPage;
}
public int getNextPage() {
return nextPage;
}
public int getPrePage() {
return prePage;
}
public int getEndPage() {
return endPage;
}
public int getTotalPage() {
return totalPage;
}
public int getTotalData() {
return totalData;
}
public List<T> getDataList() {
return dataList;
}
public void setDataList(List<T> dataList)
{
if (null != dataList && !dataList.isEmpty())
{
this.dataList = dataList;
}
}
public List<Integer> getPageList() {
return pageList;
}
}