分页后台代码封装

  1 import java.util.List;
  2 
  3 /**
  4  * 分页
  5  */
  6 public class PageUtil {
  7 
  8     private int rowcount;// 数据里面的数据总行数
  9     private int pagesize;// 一页多少行数据
 10     private int startrow;// 查询起始行
 11     private int currnav;// 当前点击的导航
 12     private int navnum;// 页面维护的固定导航个数
 13     private int navcount;// 页面数据整体导航个数 总共多少页
 14     private int begin;// 页面展示的起始导航
 15     private int end;// 页面维护展示的结束导航
 16     private int prev;// 上一页
 17     private int next;// 下一页
 18     private int first = 1;// 首页
 19     private int last;// 尾页
 20     private List pageData;// 存放分页的数据
 21 
 22     public PageUtil(int rowcount, int pagesize, int currnav, int navnum) {
 23         super();
 24         this.rowcount = rowcount;
 25         this.pagesize = pagesize;
 26         this.currnav = currnav;
 27         this.navnum = navnum;
 28         this.navcount = (int) Math.ceil((rowcount * 1.0) / pagesize);
 29         this.last = this.navcount;
 30         // 大于第一页 增强容错性
 31         this.currnav = Math.max(this.first, currnav);// 维护小于第一页 维护固定第一页 取最大
 32         this.currnav = Math.min(this.currnav, this.last);// 超过最后一页,维护最后一页 取最小
 33         // 当前页的起始行 startrow (当前点击的导航页 -1)*一页多少行数据
 34         this.startrow = (currnav - 1) * pagesize;
 35         // 处理上一页
 36         this.prev = Math.max(this.first, currnav - 1);
 37         // 处理下一页 如果当前导航页是最后一页
 38         this.next = Math.min(this.navcount, currnav + 1);
 39         // begin 页面展示的起始导航
 40         this.begin = Math.max(1, currnav - navnum / 2);
 41         // end 页面展示的结束导航
 42         this.end = Math.min(navcount, begin + navnum - 1);
 43         // 当前导航是76 -10 +1 =67 1 -10+1 = -8
 44         if ((this.end - this.begin) < (this.navnum - 1)) {
 45             this.begin = Math.max(1, this.last - navnum + 1);
 46         }
 47     }
 48 
 49     public PageUtil() {
 50         super();
 51     }
 52 
 53     public int getRowcount() {
 54         return rowcount;
 55     }
 56 
 57     public void setRowcount(int rowcount) {
 58         this.rowcount = rowcount;
 59     }
 60 
 61     public int getPagesize() {
 62         return pagesize;
 63     }
 64 
 65     public void setPagesize(int pagesize) {
 66         this.pagesize = pagesize;
 67     }
 68 
 69     public int getStartrow() {
 70         return startrow;
 71     }
 72 
 73     public void setStartrow(int startrow) {
 74         this.startrow = startrow;
 75     }
 76 
 77     public int getCurrnav() {
 78         return currnav;
 79     }
 80 
 81     public void setCurrnav(int currnav) {
 82         this.currnav = currnav;
 83     }
 84 
 85     public int getNavnum() {
 86         return navnum;
 87     }
 88 
 89     public void setNavnum(int navnum) {
 90         this.navnum = navnum;
 91     }
 92 
 93     public int getNavcount() {
 94         return navcount;
 95     }
 96 
 97     public void setNavcount(int navcount) {
 98         this.navcount = navcount;
 99     }
100 
101     public int getBegin() {
102         return begin;
103     }
104 
105     public void setBegin(int begin) {
106         this.begin = begin;
107     }
108 
109     public int getEnd() {
110         return end;
111     }
112 
113     public void setEnd(int end) {
114         this.end = end;
115     }
116 
117     public int getPrev() {
118         return prev;
119     }
120 
121     public void setPrev(int prev) {
122         this.prev = prev;
123     }
124 
125     public int getNext() {
126         return next;
127     }
128 
129     public void setNext(int next) {
130         this.next = next;
131     }
132 
133     public int getFirst() {
134         return first;
135     }
136 
137     public void setFirst(int first) {
138         this.first = first;
139     }
140 
141     public int getLast() {
142         return last;
143     }
144 
145     public void setLast(int last) {
146         this.last = last;
147     }
148 
149     public List getPageData() {
150         return pageData;
151     }
152 
153     public void setPageData(List pageData) {
154         this.pageData = pageData;
155     }
156 }

 

 

posted @ 2017-05-11 20:57  Huahi  阅读(635)  评论(0编辑  收藏  举报