分页程序(非通用版)简单版

package net.dbet.common;

import java.util.List;

/**
 * 分页类,设置currPage,pageCount,pageCodeCount,pageRows
 * */
public class Pages {
	
	private int currPage;           //当前页码
	private int pageCount;          //页总数
	private String pageBar;         //页码条字符串
	
	private int pageCodeCount=10;   //显示的页码个数
	private int halfPageCode=5;     //页码个数的一半
	
	public int getHalfPageCode() {
		return halfPageCode;
	}
	public void setHalfPageCode(int halfPageCode) {
		this.halfPageCode = halfPageCode;
	}
	public int getPageCodeCount() {
		return pageCodeCount;
	}
	public void setPageCodeCount(int pageCodeCount) {
		this.pageCodeCount = pageCodeCount;
		if(pageCodeCount%2==0)
			halfPageCode=pageCodeCount/2;
		else
			halfPageCode=pageCodeCount/2+1;
	}
	public int getCurrPage() {
		return currPage;
	}
	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}
	public String getPageBar() {
		if(this.pageCount==0) return "";
		StringBuffer sResult=new StringBuffer();
		sResult.append("[<a href='javascript:jumpPage(1);'>首页</a>]");
		if(this.currPage>1)
			sResult.append("[<a href='javascript:jumpPage("+(this.currPage-1)+");'>上一页</a>]");
		if(this.currPage-(halfPageCode-1)>1&&this.pageCount>pageCodeCount)
			sResult.append("...");
		int start=1;
		if(this.currPage>halfPageCode){
			if(this.pageCount-this.currPage<halfPageCode){
				start=this.pageCount-(pageCodeCount-1);
			}else{
				start=this.currPage-(halfPageCode-1);
			}
		}
		start=start<1?1:start;
		int end=this.pageCount;
		if(start+(pageCodeCount-1)<this.pageCount)
			end=start+(pageCodeCount-1);
		else
			end=this.pageCount;
		for(int i=start;i<=end;i++){
			if(this.currPage==i){
				sResult.append("<font color='red'>"+i+"</font>");
			}else{
				sResult.append("[<a href='javascript:jumpPage("+i+");'>"+i+"</a>]");
			}
		}
		if(end!=this.pageCount)
			sResult.append("...");
		if(this.currPage<this.pageCount)
			sResult.append("[<a href='javascript:jumpPage("+(this.currPage+1)+");'>下一页</a>]");
		sResult.append("[<a href='javascript:jumpPage("+this.pageCount+");'>尾页</a>]");
		return sResult.toString();
	}
	public void setPageBar(String pageBar) {
		this.pageBar = pageBar;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	
		
}

 

你可能感兴趣的:(JavaScript,.net)