标签:
Springmvc和velocity使用的公用后台分页
类别 [选择一个类别或键入一个新类别]
样式:
使用到的辅助类代码:
1. import java.io.Serializable;
2. import java.lang.reflect.Method;
3. import java.util.HashMap;
4. import java.util.Map;
5.
6. public class BaseBean implements Serializable
7. {
8.
9. /**
10. * serialVersionUID.
11. */
12. private static final long serialVersionUID = -6040124023440584351L;
13.
14. private String startTime;
15.
16. private String endTime;
17.
18. private String pageNo;
19.
20.
21.
22. public String getPageNo()
23. {
24.
25. return pageNo;
26. }
27.
28.
29. public void setPageNo(String pageNo)
30. {
31.
32. this.pageNo = pageNo;
33. }
34.
35. public String getStartTimeFormat()
36. {
37.
38. if (!"".equals(startTime) && this.startTime != null)
39. {
40. String[] str = startTime.split(" ");
41. return str[0];
42. }
43. return startTime;
44. }
45.
46. public String getEndTimeFormat()
47. {
48.
49. if (!"".equals(endTime) && this.endTime != null)
50. {
51. String[] str = endTime.split(" ");
52. return str[0];
53. }
54. return endTime;
55. }
56.
57. public String getStartTime()
58. {
59.
60. return startTime;
61. }
62.
63. public void setStartTime(String startTime)
64. {
65.
66. this.startTime = startTime;
67. }
68.
69. public String getEndTime()
70. {
71. return endTime;
72. }
73.
74. public void setEndTime(String endTime)
75. {
76.
77. this.endTime = endTime;
78. }
79.
80. /** 最大行数. */
81. private static final int MAX_ROWS = 9999999;
82.
83. /**
84. * 动态字段. 在ibatis文件中可用“fields.xxx”方式读取动态字段值
85. */
86. @SuppressWarnings("unchecked")
87. protected Map fields = null;
88.
89. /** 起始行数(oracle物理行号从0开始). */
90. private int start = 0;
91.
92. /**
93. * 限制条数(如果不设置结束行,缺省查所有满足条件记录).
94. */
95. private int limit = MAX_ROWS;
96.
97. /**
98. * 排序字段(例sp.spCode).
99. */
100. private String sort;
101.
102. /**
103. * 正序|反序(例ASC).
104. */
105. private String order;
106.
107. /**
108. * 设置动态字段值.
109. *
110. * @param fieldName 字段名称
111. * @param value 字段值
112. */
113. @SuppressWarnings("unchecked")
114. public void setField(String fieldName, Object value)
115. {
116.
117. if (fields == null)
118. {
119. fields = new HashMap();
120. }
121. fields.put(fieldName, value);
122. }
123.
124. /**
125. * 返回动态字段值.
126. *
127. * @param fieldName 字段名称
128. * @return 对象
130. public Object getField(String fieldName)
131. {
132.
133. if (fields == null)
134. {
135. return null;
136. }
137. return getFields().get(fieldName);
138. }
139.
140. /*
141. * @Override public String toString() { return
142. * ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE); }
143. */
144. public String getSort()
145. {
146.
147. return sort;
148. }
149.
150. public void setSort(String sort)
151. {
152.
153. this.sort = sort;
154. }
155.
156. public String getOrder()
157. {
158.
159. return order;
160. }
161.
162. public void setOrder(String order)
163. {
164.
165. this.order = order;
166. }
167.
168. public int getStart()
169. {
170.
171. return start;
172. }
173.
174. public void setStart(int start)
175. {
176.
177. this.start = start;
178. }
179.
180. @SuppressWarnings("unchecked")
181. public Map getFields()
182. {
183.
184. if (fields == null)
185. {
186. fields = new HashMap();
187. }
188. return fields;
189. }
190.
191. @SuppressWarnings("unchecked")
192. public void setFields(Map dynamicFields)
193. {
194.
195. this.fields = fields;
196. }
197.
198. public int getLimit()
199. {
200.
201. return limit;
202. }
203.
204. public void setLimit(int limit)
205. {
206.
207. this.limit = limit;
208. }
209.
210. /**
211. * 清除属性
212. */
213. @SuppressWarnings("unchecked")
214. public static void clear(Class clazz, Object nullInstanse)
215. {
216.
217. if (clazz != null && nullInstanse != null)
218. {
219. Method[] mds = clazz.getDeclaredMethods();
220. for (Method method : mds)
221. {
222. if (method.getName().startsWith("set"))
223. {
224. try
225. {
226. method.invoke(nullInstanse, new Object[] { null });
227. }
228. catch (Exception e)
229. {
230. e.printStackTrace();
231. }
232. }
233. }
234. }
235. }
236.
237. }
ParamBean:添加条件查询bean
1. public class ParamBean
2. {
3. private String name;
4.
5. private String value;
6.
7. /**
8. * 返回 name的值
9. * @return 返回 name
10. */
11. public String getName()
12. {
13. return name;
14. }
15.
16. /**
17. * 对name 进行赋值
18. * @param 对name 进行赋值
19. */
20. public void setName(String name)
21. {
22. this.name = name;
23. }
24.
25. /**
26. * 返回 value的值
27. * @return 返回 value
28. */
29. public String getValue()
30. {
31. return value;
32. }
33.
34. /**
35. * 对value 进行赋值
36. * @param 对value 进行赋值
37. */
38. public void setValue(String value)
39. {
40. this.value = value;
41. }
42.
43. }
PageDomain:使用到的实体
1. import java.io.Serializable;
2. import java.net.URLDecoder;
3. import java.text.SimpleDateFormat;
4. import java.util.ArrayList;
5. import java.util.Date;
6. import java.util.Enumeration;
7. import java.util.HashMap;
8. import java.util.List;
9. import java.util.Map;
10. import javax.servlet.http.HttpServletRequest;
11. import javax.servlet.http.HttpServletResponse;
12. import javax.servlet.http.HttpSession;
13. import org.apache.commons.lang.StringUtils;
14. import org.springframework.web.context.request.RequestContextHolder;
15. import org.springframework.web.context.request.ServletRequestAttributes;
16. import org.springframework.web.context.request.ServletWebRequest;
17.
18.
19. public class PageDomain implements Serializable {
20.
21. private static final long serialVersionUID = 1L;
22.
23. /** * 每页最大条数. */
24. private static final int MAX_PER_PAGE = 999;
25.
26. /** * 缺省每页条数. */
27. private static final int DEFAULT_PER_PAGE = 10;
28.
29. /** *首页. */
30. int firstPage = 1;
31.
32. /** *前一页. */
33. int prevPage = -1;
34.
35. /** *下一页. */
36. int nextPage = -1;
37.
38. /** *尾页. */
39. int lastPage = 1;
40.
41. /** *当前页. */
42. int pageNo = 1;
43.
44. /** *总页数. */
45. int pageCount = 1;
46.
47. /** *每页大小. */
48. int perPage = DEFAULT_PER_PAGE;
49.
50. /** * 返回总行数. */
51. int totalCount = 0;
52.
53. /** * 排序字段(例sp.spCode). */
54. String sort;
55.
56. /** * 正序|反序(例ASC). */
57. String order;
58.
59. /** * 当前请求地址 */
60. String actionUrl;
61.
62. /** 操作提示页面_提示语 */
63. private String resultMessage;
64.
65. /** 操作提示页面_跳转URL */
66. private String goUrl;
67.
68. public final String ERROR = "error";
69.
70. public final String SUCCESS = "success";
71.
72. private String startTime;
73.
74. private String endTime;
75.
76. //得到系统当前日期
77. protected String currentlyDate;
78.
79. /** 起始行数(oracle物理行号从0开始). */
80. private int start = 0;
81. /** 最大行数. */
82. private static final int MAX_ROWS = 9999999;
83. /**
84. * 限制条数(如果不设置结束行,缺省查所有满足条件记录).
85. */
86. private int limit = MAX_ROWS;
87. private List<ParamBean> paramBeans;
88.
89. private List<Integer> listNum = new ArrayList<Integer>();
90. public List<Integer> getListNum(){
91. return listNum;
92. }
93. /**
94. * 返回 paramBeans的值
95. * @return 返回 paramBeans
96. */
97. public List<ParamBean> getParamBeans()
98. {
99. return paramBeans;
100. }
101.
102. /**
103. * 对paramBeans 进行赋值
104. * @param 对paramBeans 进行赋值
105. */
106. public void setParamBeans(List<ParamBean> paramBeans)
107. {
108. this.paramBeans = paramBeans;
109. }
110.
111. /**
112. * 设置分页属性.
113. *
114. * @param domain 输入DO对象
115. */
116. public void setPagination2(com.aspire.mm.common.ipfilter.pojo.BaseDomain domain)
117. {
118.
119. // 调整每页分页数
120. if (perPage > MAX_PER_PAGE)
121. {
122. perPage = DEFAULT_PER_PAGE;
123. }
124. if (perPage <= 0)
125. {
126. perPage = DEFAULT_PER_PAGE;
127. }
128.
129. if (pageNo <= 0)
130. {
131. pageNo = 1;
132. }
133. if (null != domain)
134. {
135. // 设置分页属性: start,limit,sort,order
136. domain.setStart((pageNo - 1) * perPage);
137. domain.setLimit(perPage);
138. domain.setOrder(order);
139. }
140.
141. // 得到当前请求的URL
142. HttpServletRequest httpServletRequest = getHttpServletRequest();
143.
144. // 循环所有参数
145. Enumeration paramNames = httpServletRequest.getParameterNames();
146. paramBeans = new ArrayList<ParamBean>();
147. ParamBean paramBean = null;
148. while (paramNames.hasMoreElements())
149. {
150. // 得到当前参数
151. String paramName = (String)paramNames.nextElement();
152. // 把页号参数排除,在循环外增加
153. if (paramName.equals("pageNo"))
154. {
155. continue;
156. }
157.
158. // 取得名称所对应的全部值
159. String[] paramValues = httpServletRequest.getParameterValues(paramName);
160. String paramValue = paramValues[0];
161. if (StringUtils.isNotBlank(paramValue))
162. {
163. paramBean = new ParamBean();
164. paramBean.setName(paramName);
165. paramBean.setValue(paramValue);
166. paramBeans.add(paramBean);
167. }
168. }
169. actionUrl = httpServletRequest.getRequestURI();
170.
171. }
172.
173. public void setListNum(){
174. //获取有多少页,每次显示5页
175. if(pageNo>0){
176. //每次显示5页,如果总页数小于等于5页
177. if(pageCount>0 && pageCount<=5){
178. for(int i = 1;i<=pageCount; i++){
179. listNum.add(i);
180. }
181. }else{
182. //根据下一页判断最后几页。如果当前页大于总页数-2就根据上一页进行判断
183. if(pageNo<=pageCount-2){
184. //根据上一页进行判断前几页。
185. if(pageNo<5){
186. listNum.add(1);
187. listNum.add(2);
188. listNum.add(3);
189. listNum.add(4);
190. listNum.add(5);
191. }else{
192. listNum.add(pageNo-2);
193. listNum.add(pageNo-1);
194. listNum.add(pageNo);
195. listNum.add(pageNo+1);
196. listNum.add(pageNo+2);
197. }
198. }else{
199. //这个是最后几页
200. listNum.add(pageCount-4);
201. listNum.add(pageCount-3);
202. listNum.add(pageCount-2);
203. listNum.add(pageCount-1);
204. listNum.add(pageCount);
205. }
206. }
207. }
208. }
209. public int getStart()
210. {
211.
212. return start;
213. }
214.
215. public void setStart(int start)
216. {
217.
218. this.start = start;
219. }
220.
221. public int getLimit()
222. {
223.
224. return limit;
225. }
226.
227. public void setLimit(int limit)
228. {
229.
230. this.limit = limit;
231. }
232.
233. public String getCurrentlyDate()
234. {
235.
236. return currentlyDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
237. }
238.
239. /**
240. * 得到http session.
241. *
242. * @return http session
243. */
244. public final HttpSession getSession()
245. {
246.
247. return getHttpServletRequest().getSession(true);
248. }
249.
250. /**
251. * 得到http request.
252. *
253. * @return http request
254. */
255. public final HttpServletRequest getHttpServletRequest()
256. {
257. HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
258. return request;
259. }
260.
261. /**
262. * 得到http session.
263. *
264. * @return http request
265. */
266. public final HttpSession getHttpSession()
267. {
268.
269. HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
270. return request.getSession();
271. }
272.
273. /**
274. * 得到http response.
275. *
276. * @return http response
277. */
278. public final HttpServletResponse getHttpServletResponse()
279. {
280.
281. HttpServletResponse response = ((ServletWebRequest) RequestContextHolder.getRequestAttributes()).getResponse();
282. return response;
283. }
284.
285. public void resetBaseDomain(BaseBean domain) {
286. String startTime = domain.getStartTime();
287. if (StringUtils.isNotEmpty(startTime)) {
288. domain.setStartTime(domain.getStartTimeFormat());
289. }
290.
291. String endTime = domain.getEndTime();
292. if (StringUtils.isNotEmpty(endTime)) {
293. domain.setEndTime(domain.getEndTimeFormat());
294. }
295. }
296.
297. /**
298. * 设置分页属性.
299. *
300. * @param domain 输入DO对象
301. */
302. public void setPagination(com.aspire.mm.common.ipfilter.pojo.BaseDomain domain)
303. {
304.
305. // 调整每页分页数
306. if (perPage > MAX_PER_PAGE)
307. {
308. perPage = DEFAULT_PER_PAGE;
309. }
310. if (perPage <= 0)
311. {
312. perPage = DEFAULT_PER_PAGE;
313. }
314.
315. if (pageNo <= 0)
316. {
317. pageNo = 1;
318. }
319. // 设置分页属性: start,limit,sort,order
320. domain.setStart((pageNo - 1) * perPage);
321. domain.setLimit(perPage);
322. domain.setSort(sort);
323. domain.setOrder(order);
324.
325. //修改开始和结束时间
326. String startTime = domain.getStartTime();
327. if (StringUtils.isNotEmpty(startTime) && startTime.indexOf(":") == -1) {
328. domain.setStartTime(startTime+" 00:00:00");
329. }
330.
331. String endTime = domain.getEndTime();
332. if (StringUtils.isNotEmpty(endTime) && endTime.indexOf(":") == -1) {
333. domain.setEndTime(endTime+" 23:59:59");
334. }
335.
336. // 得到当前请求的URL
337. String queryString = getQueryString("pageNo");
338. // 将pageNo参数放在URL最后边,待模板页增加实际页号
339. if (queryString.length() == 0)
340. {
341. actionUrl = getHttpServletRequest().getRequestURI() + "?pageNo=";
342. }
343. else
344. {
345. actionUrl = getHttpServletRequest().getRequestURI() + "?" + queryString + "&pageNo=";
346. }
347.
348. }
349.
350.
351. /**
352. * 获取查询字符串
353. * @return
354. */
355. @SuppressWarnings({ "unchecked", "deprecation" })
356. public String getQueryString(String ...strings )
357. {
358. Map<String,String> filterMap = new HashMap<String, String>();
359. for (String string : strings)
360. {
361. filterMap.put(string, string);
362. }
363. HttpServletRequest httpServletRequest = getHttpServletRequest();
364.
365. // 循环所有参数
366. Enumeration paramNames = httpServletRequest.getParameterNames();
367. StringBuffer paramBuffer = new StringBuffer();
368. while (paramNames.hasMoreElements())
369. {
370. // 得到当前参数
371. String paramName = ( String ) paramNames.nextElement();
372. // 把页号参数排除,在循环外增加
373. if (filterMap.containsKey(paramName))
374. {
375. continue;
376. }
377.
378. // 取得名称所对应的全部值
379. String[] paramValues = httpServletRequest.getParameterValues(paramName);
380.
381. // 如果有多个参数,取第一个参数的值
382. String paramValue = paramValues[0];
383. if (StringUtils.isEmpty(paramValue))
384. {
385. continue;
386. }
387.
388. try {
389. paramValue = URLDecoder.decode(paramValue);
390. } catch (Exception e) {
391.
392. }
393.
394.
395. if (paramBuffer.length() == 0)
396. {
397. paramBuffer.append(paramName + "=" + paramValue);
398. }
399. else
400. {
401. paramBuffer.append("&" + paramName + "=" + paramValue);
402. }
403. }
404. return paramBuffer.toString();
405. }
406.
407. public int getFirstPage()
408. {
409.
410. return firstPage;
411. }
412.
413. public void setFirstPage(int firstPage)
414. {
415.
416. this.firstPage = firstPage;
417. }
418.
419. public int getPrevPage()
420. {
421.
422. return prevPage;
423. }
424.
425. public void setPrevPage(int prevPage)
426. {
427.
428. this.prevPage = prevPage;
429. }
430.
431. public int getNextPage()
432. {
433.
434. return nextPage;
435. }
436.
437. public void setNextPage(int nextPage)
438. {
439.
440. this.nextPage = nextPage;
441. }
442.
443. public int getLastPage()
444. {
445.
446. return lastPage;
447. }
448.
449. public void setLastPage(int lastPage)
450. {
451.
452. this.lastPage = lastPage;
453. }
454.
455. public int getPageNo()
456. {
457.
458. return pageNo;
459. }
460.
461. public void setPageNo(int pageNo)
462. {
463.
464. this.pageNo = pageNo;
465. }
466.
467. public int getPageCount()
468. {
469.
470. return pageCount;
471. }
472.
473. public void setPageCount(int pageCount)
474. {
475.
476. this.pageCount = pageCount;
477. }
478.
479. public int getPerPage()
480. {
481.
482. return perPage;
483. }
484.
485. public void setPerPage(int perPage)
486. {
487.
488. this.perPage = perPage;
489. }
490.
491. public int getTotalCount()
492. {
493.
494. return totalCount;
495. }
496.
497. public void setTotalCount(int totalCount)
498. {
499.
500. this.totalCount = totalCount;
501.
502. // 计算总页数
503. if (totalCount % perPage > 0)
504. {
505. pageCount = totalCount / perPage + 1;
506. }
507. else
508. {
509. pageCount = totalCount / perPage;
510. }
511. //设置list
512. setListNum();
513. // 首页尾页号
514. firstPage = 1;
515. lastPage = pageCount;
516.
517. // 前一页,后一页页号
518. if (pageNo == pageCount)
519. {
520. nextPage = -1;
521. }
522. else
523. {
524. nextPage = pageNo + 1;
525. }
526.
527. if (pageNo == firstPage)
528. {
529. prevPage = -1;
530. }
531. else
532. {
533. prevPage = pageNo - 1;
534. }
535. }
536.
537. public String getSort()
538. {
539.
540. return sort;
541. }
542.
543. public void setSort(String sort)
544. {
545.
546. this.sort = sort;
547. }
548.
549. public String getOrder()
550. {
551.
552. return order;
553. }
554.
555. public void setOrder(String order)
556. {
557.
558. this.order = order;
559. }
560.
561. public String getActionUrl()
562. {
563.
564. return actionUrl;
565. }
566.
567. public void setActionUrl(String actionUrl)
568. {
569.
570. this.actionUrl = actionUrl;
571. }
572.
573. public String getResultMessage()
574. {
575.
576. return resultMessage;
577. }
578.
579. public void setResultMessage(String resultMessage)
580. {
581.
582. this.resultMessage = resultMessage;
583. }
584.
585. public String getGoUrl()
586. {
587.
588. return goUrl;
589. }
590.
591. public void setGoUrl(String goUrl)
592. {
593.
594. this.goUrl = goUrl;
595. }
596.
597. public String getStartTime()
598. {
599. return startTime;
600. }
601.
602. public void setStartTime(String startTime)
603. {
604. this.startTime = startTime;
605. }
606.
607. public String getEndTime()
608. {
609. return endTime;
610. }
611.
612. public void setEndTime(String endTime)
613. {
614. this.endTime = endTime;
615. }
616.
617. protected void handleException(Throwable e) {
618. if (e instanceof BOException) {
619. BOException boException = (BOException)e;
620. if (StringUtils.isNotEmpty(boException.getMessage())) {
621. setResultMessage(boException.getMessage());
622. } else {
623. int errorCode = boException.getErrorCode();
624. //setResultMessage(Constants.errorMap.get(errorCode));
625. }
626. } else {
627. setResultMessage(e.getMessage());
628. }
629. }
630.
631. protected String getAccessListFullPath(String path) {
632. return getHttpServletRequest().getContextPath() + path;
633. }
634.
635.
636. }
BeseAction:
1. public abstract class BaseAction {
2. //设置分页对象,总页数,每页显示记录条数
3. protected void pagein(BaseDomain baseDomain, int totalCount,int perPage) {
4.
5. PageDomain pageDomain = new PageDomain();
6. HttpServletRequest request = getHttpServletRequest();
7. if(request.getParameter("pageNo")!=null&&request.getParameter("pageNo").length()!=0){
8. pageDomain.setPageNo(Integer.parseInt(request.getParameter("pageNo")));
9. }
10. pageDomain.setPerPage(perPage);//30条每页
11. pageDomain.setPagination2(baseDomain);// 将条件封装进去 setLimit setStart
12. pageDomain.setTotalCount(totalCount);// 将条件封装进去 first pre
13. pageDomain.setSort("desc");
14. request.setAttribute("bean", pageDomain);
15. }
16.
17.
18. /**
19. * 得到http request.
20. *
21. * @return http request
22. */
23. protected final HttpServletRequest getHttpServletRequest()
24. {
25. HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
26. return request;
27. }
28.
29. }
简单实现类action
1. @Controller
2. @Scope("prototype")
3. @RequestMapping("/user")
4. public class UserAction extends BaseAction{
5.
6. private static Logger logger = Logger.getLogger(XXXAction .class);
7. @Autowired
8. private userBiz userBiz;
9.
10. @RequestMapping("/list.do")
11. public String list(HttpServletRequest request, HttpServletResponse response, Model model,User user){
12. int totalCount =totalCount = userBiz.listUserCount(user);
13.
14. if(totalCount > 0){
15. try {
16. logger.debug(" 开始设置分页对象,总页数,每页显示记录条数10条");
17. pagein(userAppeal,totalCount,10);//设置分页对象,总页数,每页显示记录条数
18. userList = userBiz.listUser(user);//分页查询
19.
20. } catch (Exception e) {
21.
22. logger.error("查询用户申述所有数据失败",e);
23. return "common/error";
24. }
25. logger.info("结束查询用户申述列表");
26. request.setAttribute("users", userList);
27. }
28. return "userList";
29. }
公用的page.vm
1. <script type="text/javascript">
2. var pagevmGoUrl = function(){
3. var pageNo = jQuery(‘#pageNoInput‘).val();
4.
5. if(pageNo > 0 && pageNo <= $bean.pageCount){
6. goPage(pageNo);
7. }
8.
9. if (pageNo!=‘‘ && pageNo <= 0) {
10. alert(‘请输入大于0小于等于$bean.pageCount的数值‘);
11. $("#pageNoInput").val(‘‘);
12. //goPage(${bean.firstPage});
13. };
14. if (pageNo > $bean.pageCount) {
15. alert(‘请输入大于0小于等于$bean.pageCount的数值‘);
16. $("#pageNoInput").val(‘‘);
17. //goPage($bean.pageCount);
18. };
19. var reg = /^\d+$/;
20. if(pageNo!=‘‘&&!reg.test(pageNo))
21. {
22. alert(‘输入的页码数必须为整数‘);
23. $("#pageNoInput").val(‘‘);
24. // goPage(${bean.firstPage});
25. }
26.
27. };
28. var goPage = function(toPageNo){
29. var form = ‘<form id="page_form" method="post" action="$!{actionUrl}">‘;
30. form += ‘<input id="pageNo" name="pageNo" type="hidden" value="‘+toPageNo+‘" />‘;
31. #if($bean.paramBeans)
32. #foreach($paramBean in $bean.paramBeans)
33. form += ‘<input type="hidden" class="ios" name="$!paramBean.name" value="$!paramBean.value" />‘;
34. #end
35. #end
36. form += "</form>";
37. jQuery("body").append(form);
38. var pageForm = jQuery("#page_form");
39. pageForm.submit();
40. };
41.
42. </script>
43. <style>a{text-decoration:none;color:#2D86F2}a:hover {color:blue} </style>
44.
45. <nav class="pager mt25 ng-scope">
46. <div class="pager-jump">
47. 第 <input type="text" style="height: 25px;" value="$bean.pageNo" id="pageNoInput" onblur=‘pagevmGoUrl()‘ name="pageNoInput" class="form-control"> / $bean.pageCount页
48. <span style="color:#2D86F2;margin-left:5px;" aria-label="prevPager">跳转</span>
49. </div>
50. <ul class="pagination pagination-sm">
51. ## --------------------------首页---------------
52. #if ($bean.firstPage != $bean.pageNo)
53. <li>
54. <a href=‘javascript:void(0)‘ onclick="goPage($bean.firstPage)" aria-label="prevPager">
55. <span aria-hidden="true"><<</span>
56. </a>
57. </li>
58. #end
59. #if ($bean.firstPage == $bean.pageNo)
60. <li class="disabled">
61. <a href=‘javascript:void(0)‘ disabled = ‘true‘ aria-label="prevPager">
62. <span aria-hidden="true"><<</span>
63. </a>
64. </li>
65. #end
66. ## --------------------------上一页----------
67. #if ($bean.prevPage > 0)
68. <li>
69. <a href=‘javascript:void(0)‘ onclick="goPage($bean.prevPage)" aria-label="prev">
70. <span aria-hidden="true"><</span>
71. </a>
72. </li>
73. #end
74. #if ($bean.prevPage <= 0)
75. <li class="disabled">
76. <a href=‘javascript:void(0)‘ disabled = ‘true‘ aria-label="prev">
77. <span aria-hidden="true"><</span>
78. </a>
79. </li>
80. #end
81.
82.
83. ## ##############################################
84. #if($bean.listNum.size() !=0 )
85. #foreach($num in $bean.listNum)
86. #if($bean.pageNo == $num)
87. <li class="active"><a href=‘javascript:void(0)‘ onclick="goPage($!num)" class = "pageNoA">$!num</a></li>
88. #else
89. <li><a href=‘javascript:void(0)‘ onclick="goPage($!num)" class = "pageNoA">$!num</a></li>
90. #end
91. #end
92. #else
93. <li class="active"><a href="#">1</a></li>
94. <li><a href="#">2</a></li>
95. <li><a href="#">3</a></li>
96. <li><a href="#">4</a></li>
97. <li><a href="#">5</a></li>
98. <li>
99. #end
100. ## #################################################
101. ## ---------------下一页------------------------------------
102. #if ($bean.nextPage > 0)
103. <li>
104. <a href=‘javascript:void(0)‘ onclick="goPage($bean.nextPage)" aria-label="next">
105. <span aria-hidden="true">></span>
106. </a>
107. </li>
108. #end
109. #if($bean.nextPage < 0)
110. <li class="disabled">
111. <a href=‘javascript:void(0)‘ disabled = ‘true‘ aria-label="next">
112. <span aria-hidden="true">></span>
113. </a>
114. </li>
115. #end
116. ## --------------------最后一页----------------------------------------
117. #if ($bean.lastPage != $bean.pageNo )
118. <li>
119. <a href=‘javascript:void(0)‘ onclick="goPage($bean.lastPage)" aria-label="nextPager">
120. <span aria-hidden="true">>></span>
121. </a>
122. </li>
123. #end
124. #if($bean.pageNo == $bean.pageCount)
125. <li class="disabled">
126. <a href=‘javascript:void(0)‘ disabled = ‘true‘ aria-label="nextPager">
127. <span aria-hidden="true">>></span>
128. </a>
129. </li>
130. #end
131. ## -------------------------总页数----------------------------------------
132.
133. </ul>
134. </nav>
将page.vm引入html
1. #parse("/page.vm")
总结:
后台将第一页,最后一页,总页数,算出来.要显示的1,2,3页数放在一个list中。
将他们发到页面上去,如果是条件查询,就在页面是会生成一个form表单,当他点击第n页的时候会触发submit提交。再次将条件带过去,如此来回传输
标签:
原文地址:http://www.cnblogs.com/juansiwei/p/5558102.html