![]() |
#2
zhangheng2006-04-24 15:25
public class PageBean { int currentPage=1;//当前页数 public int totalPages=0;//总页数 int pageRecorders=5;//每页显示数 int totalRows=0;//总数据数 int pageStartRow=0;//每页的起始数 int pageEndRow;//每页的终止数 boolean hasNextPage=false;//是否有下一页 boolean hasPreviousPage=false;//是否有前一页 ArrayList arrayList; Iterator it;
public PageBean(ArrayList arrayList) { this.arrayList=arrayList; totalRows=arrayList.size(); it=arrayList.iterator(); hasPreviousPage=false; currentPage=1; if((totalRows%pageRecorders)==0) { totalPages=totalRows/pageRecorders; } else { totalPages=totalRows/pageRecorders+1; } if(currentPage>=totalPages) { hasNextPage=false; } else { hasNextPage=true; } if(totalRows<pageRecorders) { this.pageStartRow=0; this.pageEndRow=totalRows; } else { this.pageStartRow=0; this.pageEndRow=pageRecorders; } }
public void setCurrentPage(int currentPage) { this.currentPage=currentPage; } public void setPageRecorders(int pageRecorders) { this.pageRecorders=pageRecorders; } public void setHasNextPage(boolean hasNextPage) { this.hasNextPage=hasNextPage; } public void setHasPreviosPage(boolean hasPreviosPage) { this.hasPreviousPage=hasPreviousPage; } public String getCurrentPage() { return this.toString(currentPage); } public String getTotalPages() { return this.toString(totalPages); } public String getTotalRow() { return this.toString(totalRows); } public int getPageRecorders() { return pageRecorders; } public int getPageEndRow() { return pageEndRow; } public int getPageStartRow() { return pageStartRow; } public boolean isHasNextPage() { return hasNextPage; } public boolean isHasPreviousPage() { return hasPreviousPage; }
public Book[] getNextPage() { currentPage=currentPage+1; if((currentPage-1)>0) { hasPreviousPage=true; } else { hasPreviousPage=false; } if(currentPage>=totalPages) { hasNextPage=false; } else { hasNextPage=true; } Book[] books=getBooks(); return books; }
public Book[] getPreviousPage() { currentPage=currentPage-1; if(currentPage==0) { currentPage=1; } if(currentPage>=totalPages) { hasNextPage=false; } else { hasNextPage=true; } if((currentPage-1)>0) { hasPreviousPage=true; } else { hasPreviousPage=false; } Book[] books=getBooks(); return books; }
public Book[] getBooks() { if(currentPage*pageRecorders<totalRows) { pageEndRow=currentPage*pageRecorders; pageStartRow=pageEndRow-pageRecorders; } else { pageEndRow=totalRows; pageStartRow=pageRecorders*(totalPages-1); } Book[] books=new Book[pageEndRow-pageStartRow+1]; int j=0; for(int i=pageStartRow;i<pageEndRow;i++) { Book book=(Book)arrayList.get(i); books[j++]=book; } return books; }
public String toString(int temp) { String str=Integer.toString(temp); return str; } } |
各位哥哥姐姐
请教下高效简单的分页java源代码
感激不尽!!!