分页助手类


/**
* 分页操作助手类
*
*/
public class PagedList
{
protected long count; //数据的总数
protected int last; //最后一页
protected int previous;//上一页
protected int index; //当前页
protected int next; //下一页
protected boolean hasFirst; //是否首页
protected boolean hasLast; //是否最后一页
protected boolean hasNext; //是否有下一页
protected boolean hasPrevious;//是否有上一页
protected List pageList; //页面显示的页码集
protected List list; //数据集

/**
* 构造方法,构建一个分页类
*
* @param count 数据总数
* @param size 每页显示多少
* @param index 当前页
* @param list 数据集
* @return
*/
public PagedList(long count, int size, int index, List list)
{
this.list = list;
this.count=count;
this.index=index;
if(index < 1)
index = 1;
if(count % (long)size > 0L)
last = (int)(count / (long)size + 1L);
else
last = (int)(count / (long)size);
//如果当前页不是最后一页,
hasNext = hasLast = index < last;
//如果有下一页
if(hasNext)
next = index + 1;
//如果当前页不是第一页,
hasPrevious = hasFirst = index > 1;
//如果有上一页
if(hasPrevious)
previous = index - 1;
//页码集
pageList = new ArrayList();
int start = 0;
int stop = 0;
if(index <= 5)
{
start = 1;
if(last > 10)
stop = 10;
else
stop = last;
} else
{
start = index - index % 5;
if(last > start + 10)
stop = start + 10;
else
stop = last;
}
for(int i = start; i <= stop; i++)
pageList.add(Integer.valueOf(i));
}

public List getList()
{
return list;
}

public List getPageList()
{
return pageList;
}

public long getCount()
{
return count;
}

public int getPrevious()
{
return previous;
}

public int getNext()
{
return next;
}

public int getIndex()
{
return index;
}

public int getLast()
{
return last;
}

public boolean hasNext()
{
return hasNext;
}

public boolean hasPrevious()
{
return hasPrevious;
}

public boolean hasFirst()
{
return hasFirst;
}

public boolean hasLast()
{
return hasLast;
}


}


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xiaoping8411/archive/2010/04/02/5446369.aspx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值