欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

经典翻页之当前页码居中

程序员文章站 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>&nbsp;&nbsp;");
		}
		for (int i = start; i < pageNo; i++) {
			buffer.append(urlstart + i + ">[" + i + "]</a>&nbsp;&nbsp;");
		}
		buffer.append("&nbsp;" + pageNo + "&nbsp;&nbsp;&nbsp;");
		for (int i = pageNo + 1; i <= end; i++) {
			buffer.append(urlstart + i + ">[" + i + "]</a>&nbsp;&nbsp;");
		}
		if (pageNo != pages) {
			buffer.append(urlstart + (pageNo + 1) + ">下一页</a>&nbsp;&nbsp;");
		}
		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("&nbsp;&nbsp;" + 1 + "&nbsp;&nbsp;");
		for (int i = 2; i <= (pages > 10 ? 10 : pages); i++) {
			buffer.append("<a class=pageCss href="
					+ dataCenterParam.getPageJumpURL() + i + ">[" + i
					+ "]</a>&nbsp;&nbsp;&nbsp;&nbsp;");
		}
		if (pages > 10) {
			buffer.append("<a class=pageCss href="
					+ dataCenterParam.getPageJumpURL() + 2
					+ ">下一页</a>&nbsp;&nbsp;");
		}
		return buffer.toString();
	}

}

 

//简单点出分页页码算法. 

相关标签: j2ee code

上一篇:

下一篇: