ad5081d3
孙向锦
初始化项目
|
1
2
3
4
5
6
|
package com.fh.entity;
import com.fh.util.Const;
import com.fh.util.PageData;
import com.fh.util.Tools;
|
ad5081d3
孙向锦
初始化项目
|
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
|
public class Page {
private int showCount; //每页显示记录数
private int totalPage; //总页数
private int totalResult; //总记录数
private int currentPage; //当前页
private int currentResult; //当前记录起始索引
private boolean entityOrField; //true:需要分页的地方,传入的参数就是Page实体;false:需要分页的地方,传入的参数所代表的实体拥有Page属性
private String pageStr; //最终页面显示的底部翻页导航,详细见:getPageStr();
private PageData pd = new PageData();
public Page(){
try {
this.showCount = Integer.parseInt(Tools.readTxtFile(Const.PAGE));
} catch (Exception e) {
this.showCount = 15;
}
}
public int getTotalPage() {
if(totalResult%showCount==0)
totalPage = totalResult/showCount;
else
totalPage = totalResult/showCount+1;
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalResult() {
return totalResult;
}
public void setTotalResult(int totalResult) {
this.totalResult = totalResult;
}
public int getCurrentPage() {
if(currentPage<=0)
currentPage = 1;
if(currentPage>getTotalPage())
currentPage = getTotalPage();
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
|
fd0087a8
孙向锦
添加英语语言
|
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
|
private String total = "共" ;
private String articles = "条";
private String frist = "首页" ;
private String previous = "上一页";
private String next = "下一页";
private String tail = "尾页" ;
private String jump = "跳转" ;
private String pageNumber = "页码";
private String displayNumber = "显示条数" ;
public void setLangIsChina(boolean is){
if(is){
total = "共" ;
articles = "条";
frist = "首页" ;
previous = "上一页";
next = "下一页";
tail = "尾页" ;
jump = "跳转" ;
pageNumber = "页码";
displayNumber = "显示条数" ;
}else{
total = "" ;
articles = " articles";
frist = "Frist" ;
previous = "Previous";
next = "Next";
|
f19da108
孙向锦
添加英语对应的修改
|
87
88
89
|
tail = "Last" ;
jump = "Goto" ;
pageNumber = "PageNo.";
|
fd0087a8
孙向锦
添加英语语言
|
90
91
92
|
displayNumber = "Display Number" ;
}
}
|
ad5081d3
孙向锦
初始化项目
|
93
94
95
96
97
98
|
//拼接分页 页面及JS函数
public String getPageStr() {
StringBuffer sb = new StringBuffer();
if(totalResult>0){
sb.append(" <ul class=\"pagination pull-right no-margin\">\n");
if(currentPage==1){
|
fd0087a8
孙向锦
添加英语语言
|
99
|
sb.append(" <li><a>" + total +totalResult+articles + "</a></li>\n");
|
f19da108
孙向锦
添加英语对应的修改
|
100
|
sb.append(" <li><span style='padding:0'><input type=\"number\" value=\"\" id=\"toGoPage\" style=\"width:80px;text-align:center;float:left\" placeholder=\"" + pageNumber + "\"/></span></li>\n");
|
fd0087a8
孙向锦
添加英语语言
|
101
102
103
|
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"toTZ();\" class=\"btn btn-mini btn-success\">" + jump + "</a></li>\n");
sb.append(" <li><a>" + frist + "</a></li>\n");
sb.append(" <li><a>" + previous + "</a></li>\n");
|
ad5081d3
孙向锦
初始化项目
|
104
|
}else{
|
fd0087a8
孙向锦
添加英语语言
|
105
|
sb.append(" <li><a>"+ total +"<font color=red>"+totalResult+"</font>" + articles + "</a></li>\n");
|
f19da108
孙向锦
添加英语对应的修改
|
106
|
sb.append(" <li><input type=\"number\" value=\"\" id=\"toGoPage\" style=\"width:80px;text-align:center;float:left\" placeholder=\"" + pageNumber + "\"/></li>\n");
|
fd0087a8
孙向锦
添加英语语言
|
107
108
109
|
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"toTZ();\" class=\"btn btn-mini btn-success\">" + jump + "</a></li>\n");
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage(1)\">" + frist + "</a></li>\n");
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+(currentPage-1)+")\">" + previous + "</a></li>\n");
|
ad5081d3
孙向锦
初始化项目
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
}
int showTag = 5;//分页标签显示数量
int startTag = 1;
if(currentPage>showTag){
startTag = currentPage-1;
}
int endTag = startTag+showTag-1;
for(int i=startTag; i<=totalPage && i<=endTag; i++){
if(currentPage==i)
sb.append("<li class=\"active\"><a><font color='white'>"+i+"</font></a></li>\n");
else
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+i+")\">"+i+"</a></li>\n");
}
if(currentPage==totalPage){
|
fd0087a8
孙向锦
添加英语语言
|
124
125
|
sb.append(" <li><a>" + next + "</a></li>\n");
sb.append(" <li><a>" + tail + "</a></li>\n");
|
ad5081d3
孙向锦
初始化项目
|
126
|
}else{
|
fd0087a8
孙向锦
添加英语语言
|
127
128
|
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+(currentPage+1)+")\">" + next + "</a></li>\n");
sb.append(" <li style=\"cursor:pointer;\"><a onclick=\"nextPage("+totalPage+")\">" + tail + "</a></li>\n");
|
ad5081d3
孙向锦
初始化项目
|
129
|
}
|
fd0087a8
孙向锦
添加英语语言
|
130
131
|
sb.append(" <li><a>" + total +totalResult+articles + "</a></li>\n");
sb.append(" <li><span class=\"enter\"><select title='" + displayNumber + "' style=\"width:55px;float:left;height:32px;margin-top:1px;border:0\" onchange=\"changeCount(this.value)\">\n");
|
ad5081d3
孙向锦
初始化项目
|
132
133
134
135
136
137
138
139
140
141
142
|
sb.append(" <option value='"+showCount+"'>"+showCount+"</option>\n");
sb.append(" <option value='10'>10</option>\n");
sb.append(" <option value='20'>20</option>\n");
sb.append(" <option value='30'>30</option>\n");
sb.append(" <option value='40'>40</option>\n");
sb.append(" <option value='50'>50</option>\n");
sb.append(" <option value='60'>60</option>\n");
sb.append(" <option value='70'>70</option>\n");
sb.append(" <option value='80'>80</option>\n");
sb.append(" <option value='90'>90</option>\n");
sb.append(" <option value='99'>99</option>\n");
|
4f32cbf7
孙向锦
更新新东方服务界面维护文档
|
143
|
sb.append(" </select></span>\n");
|
ad5081d3
孙向锦
初始化项目
|
144
145
146
147
148
149
150
|
sb.append(" </li>\n");
sb.append("</ul>\n");
sb.append("<script type=\"text/javascript\">\n");
//换页函数
sb.append("function nextPage(page){");
|
4f32cbf7
孙向锦
更新新东方服务界面维护文档
|
151
|
sb.append("\n if(top && top.jzts)\n{\n top.jzts();\n}\n");
|
ad5081d3
孙向锦
初始化项目
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
sb.append(" if(true && document.forms[0]){\n");
sb.append(" var url = document.forms[0].getAttribute(\"action\");\n");
sb.append(" if(url.indexOf('?')>-1){url += \"&"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n");
sb.append(" else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n");
sb.append(" url = url + page + \"&" +(entityOrField?"showCount":"page.showCount")+"="+showCount+"\";\n");
sb.append(" document.forms[0].action = url;\n");
sb.append(" document.forms[0].submit();\n");
sb.append(" }else{\n");
sb.append(" var url = document.location+'';\n");
sb.append(" if(url.indexOf('?')>-1){\n");
sb.append(" if(url.indexOf('currentPage')>-1){\n");
sb.append(" var reg = /currentPage=\\d*/g;\n");
sb.append(" url = url.replace(reg,'currentPage=');\n");
sb.append(" }else{\n");
sb.append(" url += \"&"+(entityOrField?"currentPage":"page.currentPage")+"=\";\n");
sb.append(" }\n");
sb.append(" }else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n");
sb.append(" url = url + page + \"&" +(entityOrField?"showCount":"page.showCount")+"="+showCount+"\";\n");
sb.append(" document.location = url;\n");
sb.append(" }\n");
sb.append("}\n");
//调整每页显示条数
sb.append("function changeCount(value){");
|
4f32cbf7
孙向锦
更新新东方服务界面维护文档
|
176
|
sb.append(" \n if(top && top.jzts)\n{\n top.jzts();\n}\n");
|
ad5081d3
孙向锦
初始化项目
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
sb.append(" if(true && document.forms[0]){\n");
sb.append(" var url = document.forms[0].getAttribute(\"action\");\n");
sb.append(" if(url.indexOf('?')>-1){url += \"&"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n");
sb.append(" else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n");
sb.append(" url = url + \"1&" +(entityOrField?"showCount":"page.showCount")+"=\"+value;\n");
sb.append(" document.forms[0].action = url;\n");
sb.append(" document.forms[0].submit();\n");
sb.append(" }else{\n");
sb.append(" var url = document.location+'';\n");
sb.append(" if(url.indexOf('?')>-1){\n");
sb.append(" if(url.indexOf('currentPage')>-1){\n");
sb.append(" var reg = /currentPage=\\d*/g;\n");
sb.append(" url = url.replace(reg,'currentPage=');\n");
sb.append(" }else{\n");
sb.append(" url += \"1&"+(entityOrField?"currentPage":"page.currentPage")+"=\";\n");
sb.append(" }\n");
sb.append(" }else{url += \"?"+(entityOrField?"currentPage":"page.currentPage")+"=\";}\n");
sb.append(" url = url + \"&" +(entityOrField?"showCount":"page.showCount")+"=\"+value;\n");
sb.append(" document.location = url;\n");
sb.append(" }\n");
sb.append("}\n");
//跳转函数
sb.append("function toTZ(){");
sb.append("var toPaggeVlue = document.getElementById(\"toGoPage\").value;");
sb.append("if(toPaggeVlue == ''){document.getElementById(\"toGoPage\").value=1;return;}");
sb.append("if(isNaN(Number(toPaggeVlue))){document.getElementById(\"toGoPage\").value=1;return;}");
sb.append("nextPage(toPaggeVlue);");
sb.append("}\n");
sb.append("</script>\n");
}
pageStr = sb.toString();
return pageStr;
}
public void setPageStr(String pageStr) {
this.pageStr = pageStr;
}
public int getShowCount() {
return showCount;
}
public void setShowCount(int showCount) {
this.showCount = showCount;
}
public int getCurrentResult() {
currentResult = (getCurrentPage()-1)*getShowCount();
if(currentResult<0)
currentResult = 0;
return currentResult;
}
public void setCurrentResult(int currentResult) {
this.currentResult = currentResult;
}
public boolean isEntityOrField() {
return entityOrField;
}
public void setEntityOrField(boolean entityOrField) {
this.entityOrField = entityOrField;
}
public PageData getPd() {
return pd;
}
public void setPd(PageData pd) {
this.pd = pd;
}
|
fd0087a8
孙向锦
添加英语语言
|
252
|
|
ad5081d3
孙向锦
初始化项目
|
253
|
}
|