分页助手类

  1. /**
  2. * 分页操作助手类
  3. *
  4. */ 
  5. public class PagedList
  6.     protected long count; //数据的总数 
  7.     protected int last; //最后一页 
  8.     protected int previous;//上一页 
  9.     protected int index; //当前页 
  10.     protected int next; //下一页 
  11.     protected boolean hasFirst; //是否首页 
  12.     protected boolean hasLast; //是否最后一页 
  13.     protected boolean hasNext; //是否有下一页 
  14.     protected boolean hasPrevious;//是否有上一页 
  15.     protected List pageList;  //页面显示的页码集 
  16.     protected List list;  //数据集 
  17.      
  18.     /**
  19.        * 构造方法,构建一个分页类
  20.        *
  21.        * @param count 数据总数
  22.        * @param size  每页显示多少
  23.        * @param index 当前页
  24.        * @param list  数据集
  25.        * @return
  26.       */ 
  27.     public PagedList(long count, int size, int index, List list) 
  28.     { 
  29.         this.list = list; 
  30.         this.count=count; 
  31.         this.index=index; 
  32.         if(index < 1
  33.             index = 1
  34.         if(count % (long)size > 0L) 
  35.             last = (int)(count / (long)size + 1L); 
  36.         else 
  37.             last = (int)(count / (long)size); 
  38.         //如果当前页不是最后一页, 
  39.         hasNext = hasLast = index < last; 
  40.         //如果有下一页 
  41.         if(hasNext) 
  42.             next = index + 1
  43.         //如果当前页不是第一页, 
  44.         hasPrevious = hasFirst = index > 1
  45.         //如果有上一页 
  46.         if(hasPrevious) 
  47.             previous = index - 1
  48.         //页码集 
  49.         pageList = new ArrayList(); 
  50.         int start = 0
  51.         int stop = 0
  52.         if(index <= 5
  53.         { 
  54.             start = 1
  55.             if(last > 10
  56.                 stop = 10
  57.             else 
  58.                 stop = last; 
  59.         } else 
  60.         { 
  61.             start = index - index % 5
  62.             if(last > start + 10
  63.                 stop = start + 10
  64.             else 
  65.                 stop = last; 
  66.         } 
  67.         for(int i = start; i <= stop; i++) 
  68.             pageList.add(Integer.valueOf(i)); 
  69.     } 
  70.  
  71.     public List getList() 
  72.     { 
  73.         return list; 
  74.     } 
  75.  
  76.     public List getPageList() 
  77.     { 
  78.         return pageList; 
  79.     } 
  80.  
  81.     public long getCount() 
  82.     { 
  83.         return count; 
  84.     } 
  85.  
  86.     public int getPrevious() 
  87.     { 
  88.         return previous; 
  89.     } 
  90.  
  91.     public int getNext() 
  92.     { 
  93.         return next; 
  94.     } 
  95.  
  96.     public int getIndex() 
  97.     { 
  98.         return index; 
  99.     } 
  100.  
  101.     public int getLast() 
  102.     { 
  103.         return last; 
  104.     } 
  105.  
  106.     public boolean hasNext() 
  107.     { 
  108.         return hasNext; 
  109.     } 
  110.  
  111.     public boolean hasPrevious() 
  112.     { 
  113.         return hasPrevious; 
  114.     } 
  115.  
  116.     public boolean hasFirst() 
  117.     { 
  118.         return hasFirst; 
  119.     } 
  120.  
  121.     public boolean hasLast() 
  122.     { 
  123.         return hasLast; 
  124.     } 
  125.  
  126.     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值