码迷,mamicode.com
首页 > 编程语言 > 详细

java分页

时间:2014-11-06 21:24:05      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:blog   ar   java   数据   div   art   log   size   as   

package entity;

public class Page { //记录当前页的状态信息
private int num; //当前页号,采用自然数计数 1,2,3,...
private int size; //一页显示多少个数据
private int rowCount; //记录的总数目(一共有多少个数据)
private int pageCount; //页面总数(n页)
private int startRow; //当前页开始行号,第一行是0行 
private int first=1; //第一页 页号
private int last; //最后页 页号
private int next; //下一页 页号
private int prev; //前一页 页号
private int start; // 页号式导航, 起始页号
private int end; // 页号式导航, 结束页号
private int numCount = 4; // 页号式导航, 最多显示页号数量为numCount+1;这里显示5页。

public Page(int size, String str_num, int rowCount) {

int num = 1;
if (str_num != null) { //str_num,起始记录号
num = Integer.parseInt(str_num);
}
this.num = num;
this.size = size;
this.rowCount = rowCount;
this.pageCount = (int) Math.ceil((double) rowCount / size); //**获取页数的总数,ceil是进1取整
this.num = Math.min(this.num, pageCount); //当前页号最大值为pageCount
this.num = Math.max(1, this.num); //当前页号最小值为1
this.startRow = (this.num-1) * size; //开始行号为 0行
this.last = this.pageCount; //最后一页页号为pageCount
this.next = Math.min(this.pageCount, this.num+1); //最后一页为pageCount或者为当前页+1
this.prev = Math.max(1, this.num-1); //最前一页为1或者为当前页-1

// 计算page 控制
//当点击7的时候只出现5到9,当点击8的时候,只出现6到10
//若是出现1-5或者6-10,则可改为:if((this.num+1)%(numCount+1)==0){
//start=(this.num+1)%(numCount+1)-1*(numCount+1)+1;}
//else{ start=this.num/(numCount+1)*(numCount+1)+1;}
//比如15和14
//本页显示页号从多少页开始,eg:7-4/2=5(第七页就是从第五页开始)
start = Math.max(this.num - numCount/2, first); 

//本页显示页号在多少页号结束 eg:5+4=9(若本页是第七页,则本页开始页为5,结束页为9,每页显示5个)
end = Math.min(start + numCount, last); 
if (end - start < numCount) { //如果记录数小于4
start = Math.max(end - numCount, 1); //开始页为1和结束页号-记录数的最大值
}
}

public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getRowCount() {
return rowCount;
}
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getStartRow() {
return startRow;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public int getFirst() {
return first;
}
public void setFirst(int first) {
this.first = first;
}
public int getLast() {
return last;
}
public void setLast(int last) {
this.last = last;
}
public int getNext() {
return next;
}
public void setNext(int next) {
this.next = next;
}
public int getPrev() {
return prev;
}
public void setPrev(int prev) {
this.prev = prev;
}
public int getStart() {
return start;
}

public void setStart(int start) {
this.start = start;
}

public int getEnd() {
return end;
}

public void setEnd(int end) {
this.end = end;
}

public int getNumCount() {
return numCount;
}

public void setNumCount(int numCount) {
this.numCount = numCount;
}
}

  

java分页

标签:blog   ar   java   数据   div   art   log   size   as   

原文地址:http://www.cnblogs.com/JAYIT/p/4079702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!