经典翻页之当前页码居中
程序员文章站
2024-01-07 21:41:34
...
package com.surfilter.datacenterweb.util.page; import com.surfilter.datacenterweb.bean.DataCenterParam; import com.surfilter.datacenterweb.util.ContextUtil; public class SutraPage { private static DataCenterParam dataCenterParam = (DataCenterParam) ContextUtil .getBean("dataCenterParam"); /** * 分页使用工具方法 * @param pageNo * @param pages * @return */ public static String formatPage(Integer pageNo, Integer pages) { String urlstart = "<a class=pageCss href=" + dataCenterParam.getPageJumpURL(); StringBuffer buffer = new StringBuffer(); int start = pageNo - 10 > 0 ? pageNo - 10 : 1; int end = pageNo + 9 > pages ? pages : pageNo + 9; if (pageNo != 1) { buffer.append(urlstart + (pageNo - 1) + ">上一页</a> "); } for (int i = start; i < pageNo; i++) { buffer.append(urlstart + i + ">[" + i + "]</a> "); } buffer.append(" " + pageNo + " "); for (int i = pageNo + 1; i <= end; i++) { buffer.append(urlstart + i + ">[" + i + "]</a> "); } if (pageNo != pages) { buffer.append(urlstart + (pageNo + 1) + ">下一页</a> "); } return buffer.toString(); } public static void main(String[] args) { System.out.println(SutraPage.formatPage(5, 23)); } /** * 首次查询分页显示工具方法 * @param pages * @return */ public static String formatPage(Integer pages) { StringBuffer buffer = new StringBuffer(); buffer.append(" " + 1 + " "); for (int i = 2; i <= (pages > 10 ? 10 : pages); i++) { buffer.append("<a class=pageCss href=" + dataCenterParam.getPageJumpURL() + i + ">[" + i + "]</a> "); } if (pages > 10) { buffer.append("<a class=pageCss href=" + dataCenterParam.getPageJumpURL() + 2 + ">下一页</a> "); } return buffer.toString(); } }
//简单点出分页页码算法.