package cn.pdsu;

/**
 * 开始页,结束页封装
 * 
 * @author 作者:user
 * @version 创建时间:2011-7-19 上午03:08:25
 */
public class PageIndex {
	/**
	 * 结束页
	 */
	private int endIndex;

	/**
	 * 开始页
	 */
	private int startIndex;

	/**
	 * 计算开始页和结束页
	 * 
	 * @param viewpagecount
	 *            页面中要显示的页面个数
	 * @param currentPage
	 *            当前页
	 * @param totalpage
	 *            总页面数
	 * @return PageIndex 记录开始页(startindex)和结束页(endindex)
	 */
	public static PageIndex getPageIndex(int viewpagecount, int currentPage,
			int totalpage) {
		int startpage = currentPage
				- (viewpagecount % 2 == 0 ? viewpagecount / 2 - 1
						: viewpagecount / 2);
		int endpage = currentPage + viewpagecount / 2;
		if (startpage < 1) {
			startpage = 1;
			if (totalpage >= viewpagecount)
				endpage = viewpagecount;
			else
				endpage = totalpage;
		}
		if (endpage > totalpage) {
			endpage = totalpage;
			if ((endpage - viewpagecount) > 0)
				startpage = endpage - viewpagecount + 1;
			else
				startpage = 1;
		}
		return new PageIndex(startpage, endpage);
	}

	public PageIndex(int startIndex, int endIndex) {
		this.startIndex = startIndex;
		this.endIndex = endIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

}
最近下载更多
asddwh  LV12 2023年12月29日
wuge123  LV8 2023年6月12日
1719863922  LV11 2022年6月17日
刚刚vv谭v  LV4 2022年1月4日
微信网友_5768552477921280  LV6 2022年1月2日
17771013609  LV4 2021年12月31日
fesdfs  LV1 2021年12月20日
3089559272  LV11 2021年12月17日
龙门客栈  LV9 2021年12月16日
 LV5 2021年12月15日
最近浏览更多
沈从文  LV2 2023年12月31日
asddwh  LV12 2023年12月25日
wodewode  LV1 2023年12月23日
微信网友_6786215447367680  LV4 2023年12月23日
好哇好哇还是 2023年12月20日
暂无贡献等级
颜菜菜  LV2 2023年12月19日
fff2003  LV6 2023年11月20日
sunshine9920  LV12 2023年11月7日
卢本伟不开挂  LV4 2023年10月22日
zdfxcv  LV1 2023年10月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友