分页

分页算法优化与实现
//计算分页
	private void getPage(){
		//计算总页数
		if (getRowCount() % getNumber() == 0) {
			setPageCount(getRowCount() / getNumber());
		} else {
			setPageCount(getRowCount() / getNumber() + 1);
		}
		//计算起始坐标
		setFrom((getCurrentPage()-1)*getNumber());
		
		int indexSum = 6;//索引的sum值
		int startIndex = 0;
		int endIndex = 0;
		
		//计算出索引的位置 
		if (getPageCount() > indexSum) {
			if (getCurrentPage() > indexSum/2) {	//如果当前页大于分割数量的一半就开始分页
				//最后几页的算法
				if (getCurrentPage() >= (getPageCount() - indexSum)) {	//如果当前页大于等于总页数减去分割数量的一半
					if(getCurrentPage() == getPageCount()){		//如果当前页等于总页数不在往后加页数
						endIndex = (((getCurrentPage() - indexSum/2) + indexSum) - indexSum/2);
					}else{
						endIndex = (((getCurrentPage() - indexSum/2) + indexSum) - indexSum/2 + 2);
					}
				}else{
					endIndex = ((getCurrentPage() - indexSum/2) + indexSum);
				}
				
				if(endIndex>getPageCount()){
					endIndex = getPageCount();
				}
				startIndex = endIndex - indexSum + 1;
				
			}else{
				startIndex = 1;
				endIndex = indexSum;
			}
		}else{//原始的那种分页
			startIndex = 1;
			endIndex = getPageCount();
		}
        
        for (int i = startIndex; i <= endIndex; i++) {
			paginList.add(i);
		}
	}

  

转载于:https://www.cnblogs.com/suncan0/p/5378402.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值