JAVA—咖啡馆

——欢迎访问rogerfan的博客,常来《JAVA——咖啡馆》坐坐,喝杯浓香的咖啡,彼此探讨一下JAVA技术,交流工作经验,分享JAVA带来的快乐!本网站部分转载文章,如果有版权问题请与我联系。

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

只有注册用户登录后才能发表评论。


网站导航: