- /**
- * 分页操作助手类
- *
- */
- 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;
- }
- }
分页助手类
最新推荐文章于 2024-04-15 19:14:30 发布