在struts-config.xml里配置
PageBean這個類是進行分頁的:
package com.xiaozhi.pagebean;
public class PageBean
{
//設置當前頁數
private int currentPage = 0 ;
//一共有多少條數據
private int countdata = 0 ;
//1頁里應該有多少數據
private int everypage = 0 ;
public int getCurrentPage()
{
if(countdata <= 0)
{
return 0 ;
}
return this.currentPage;
}
//設置當前頁的并進行判斷
public void setCurrentPage(int currentPage)
{
int countpage = 0 ;
countpage = this.getCountPage() ;
if(currentPage < 0)
{
this.currentPage = 0 ;
return ;
}
else if(currentPage >= countpage)
{
this.currentPage = countpage-1 ;
return ;
}
this.currentPage = currentPage;
}
public int getCountdata()
{
return countdata;
}
public void setCountdata(int countdata)
{
this.countdata = countdata;
}
public int getEverypage()
{
return everypage;
}
public void setEverypage(int everypage)
{
this.everypage = everypage;
}
//得到一共有多少頁
public int getCountPage()
{
if(countdata%everypage == 0)
{
return countdata/everypage ;
}
else
{
return countdata/everypage+1 ;
}
}
//得到起始頁的數據(是當前頁的開始數據)
public int getBeginData()
{
// System.out.println("*****@@@@"+this.currentPage+"*********") ;
//
// System.out.println("*****"+this.currentPage * this.countdata+"*********") ;
return this.currentPage * this.everypage ;
}
//得到結尾的數據(是當前頁的最后的數據)
public int getEndData()
{
// System.out.println("%%%%%%%%%%"+((this.currentPage+1)*this.everypage-1)+"%%%%%%%%%%%%%%") ;
return (this.currentPage+1)*this.everypage-1 ;
}
}
posted on 2006-04-17 11:07
xiaozhi 閱讀(315)
評論(0) 編輯 收藏