⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagebean.java

📁 bbs struts
💻 JAVA
字号:
package page;
import bean.Book;
import java.util.*;
/**
 * @作者 李敏强
 * Struts分页显示逻辑Bean
 */
public class PageBean {

 int currentPage;  //当前页
public int totalPages=0;  //总页数
 int pageRecorders=5;//每页5条数据
 int totalRows=0;  //总数据数
 int pageStartRow=0;//每页的起始数
 int pageEndRow=0;  //每页显示数据的终止数
 boolean hasNextPage=false; //是否有下一页
 boolean hasPreviousPage=false; //是否有前一页
 //ArrayList arrayList;
 Iterator Topics;
 
public PageBean(){}
 
public PageBean(int totalrow,int current){
	totalRows=totalrow;
 currentPage=current;

 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;   
    }

}

 /**
  * @return Returns the currentPage.
  */
 public String getCurrentPage() {
  return this.toString(currentPage);
 }
 /**
  * @param currentPage The currentPage to set.
  */
 public void setCurrentPage(int currentPage) {
  this.currentPage = currentPage;
 }
 /**
  * @return Returns the pageRecorders.
  */
 public int getPageRecorders() {
  return pageRecorders;
 }
 /**
  * @param pageRecorders The pageRecorders to set.
  */
 public void setPageRecorders(int pageRecorders) {
  this.pageRecorders = pageRecorders;
 }
 /**
  * @return Returns the pageEndRow.
  */
 public int getPageEndRow() {
  return pageEndRow;
 }
 /**
  * @return Returns the pageStartRow.
  */
 public int getPageStartRow() {
  return pageStartRow;
 }
 /**
  * @return Returns the totalPages.
  */
 public String getTotalPages() {
 
  return this.toString(totalPages);
 }
 /**
  * @return Returns the totalRows.
  */
 public String getTotalRows() {
  return this.toString(totalRows);
 }
 /**
  * @return Returns the hasNextPage.
  */
 public boolean isHasNextPage() {
  return hasNextPage;
 }
 /**
  * @param hasNextPage The hasNextPage to set.
  */
 public void setHasNextPage(boolean hasNextPage) {
  this.hasNextPage = hasNextPage;
 }
 /**
  * @return Returns the hasPreviousPage.
  */
 public boolean isHasPreviousPage() {
  return hasPreviousPage;
 }
 /**
  * @param hasPreviousPage The hasPreviousPage to set.
  */
 public void setHasPreviousPage(boolean hasPreviousPage) {
  this.hasPreviousPage = hasPreviousPage;
 }
public Book[] getNextPage(){
 
 currentPage=currentPage+1;
 System.out.println("PageBean.getNextPage()正在执行;");
 System.out.println("参数currentPage="+currentPage);

 if((currentPage-1)>0)
 {
  hasPreviousPage=true; 
 }
    else
    {
     hasPreviousPage=false; 
    }
 
 if(currentPage>=totalPages) 
 {
  hasNextPage=false; 
 }
 else
 {
  hasNextPage=true;
 }
 System.out.println("参数hasNextPage="+hasNextPage);
 System.out.println("准备执行PageBean.getBooks()");
 Book[] books=getBooks();
 this.description();
 
 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();
 this.description();
 return books;
}

public Book[] getBooks(){
 System.out.println("pageBean.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];
 
 System.out.println("pageStartRow="+pageStartRow);
 System.out.println("pageEndRow="+pageEndRow);
  int j=0; 
 for(int i=pageStartRow;i<pageEndRow;i++)
 {
 
  Book book=(Book)arrayList.get(i); 
  books[j++]=book;
 
 }
 System.out.println("要显示的页面数据已经封装,具体信息如下:");
 this.description();
 return books;
}

public String toString(int temp)
{
String str=Integer.toString(temp);
return str;
}

public void setTopics(Iterator t)
{
	topics=t;
	
}
public Iterator getTopics()
{
	return topics;
}

public void description()
{

   String description="共有数据数:"+this.getTotalRows()+

   "共有页数: "+this.getTotalPages() +

   "当前页数为:"+this.getCurrentPage()+
   
   " 是否有前一页: "+this.isHasPreviousPage() +

   " 是否有下一页:"+this.isHasNextPage()+

   " 开始行数:"+this.getPageStartRow()+

   " 终止行数:"+this.getPageEndRow();

   System.out.println(description);

}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -