java 写的分页类(自家用)

王朝java/jsp·作者佚名  2006-01-09
宽屏版  字体: |||超大  

import java.util.Collection;

import java.util.Iterator;

import com.soohuo.se.member.ds.usercomment.AppUserCommentVO;

import com.soohuo.se.common.ShowGrade;

import com.soohuo.framework.GenericException;

import java.util.ArrayList;

/*

*@param count 记录的总共条数

*@param url 翻页要跳转的页面url

*@param infoSum 每页显示的条数

*@param page 当前页

*@param arr 存放结果集的ArrayList

*@return 生成的结果

*@throws GenericException

*针对oracle数据库,采用sql语句完成分页

*sql语句格式为:

*select * from (select rownum num,列 from 表 where ...and...orderby....)where num between 开始(从1开始) and 结束

*/

public class Pagination {

//设置常用参数

public void setParam(int count,String url,int infoSum,int page)

{

if(page==0||page

{

page = 1;

}

this.page=page;

this.url=url+"&page=";

this.infoSum=infoSum;

this.count=count;

}

public static int infoSum=3;//每页显示的条数

public static int count=0; //总共的条数

public static String url; //跳转地址

public static int page; //当前页

//设置总共页数

public void setInfoSum(int infoSum)

{

this.infoSum=infoSum;

}

//取得总共条数

public int getCount()

{

return count;

}

//取得每页显示数

public int getInfoSum()

{

return infoSum;

}

//取得总共的页数

public int getSumPage()

{

int pageSum=count/infoSum;

if(count%infoSum!=0)

pageSum+=1;

return pageSum;

}

//设置跳转用的js

public String setJs()

{

String js="";

return js;

}

//设置翻页主体

public String getPageBody(ArrayList arr) throws

GenericException {

String str="";

Iterator it=arr.iterator();

ShowGrade showGrade=new ShowGrade();

while(it.hasNext())

{

AppUserCommentVO vo=(AppUserCommentVO)it.next();

str+=showGrade.ShowUserCommentGrade(vo.getCommentId())+"";

str+="";

str+="

src='/images/ping.gif' 发 表 人:["+vo.getUserId()+"]

";

//str+="

src='/images/ping.gif' 发 表 人:["+vo.getUserName()+"]

";

str+="";

str+="";

str+="点评:

"+vo.getCommentInfo()+"

";

str+="";

}

this.page=0;

return str;

}

//设置翻页头

public String getPageHead()

{

int pageSum=this.getSumPage();

String head=this.setJs()+"共有"+pageSum+"页 当前是"+page+"页";

if(pageSum1 && page

{

head+=" 跳到第 ";

for(int i=1;i

{

if(i==page){

head+=""+i+"";

}

else{

head+=""+i+"";

}

}

head+="";

}

head+="

";

return head;

}

//设置翻页尾显示

public String getPageFoot(int pa)

{

int pageSum=this.getSumPage();

int p=pa;

int nextPage=0;//下页

nextPage=p+1;

int upPage=0;

upPage=p-1;//上页

String foot="";

if(p1)

{

foot+="首页  上一页";

}

if(pageSum1 && p

{

foot+=" 下一页 尾页";

}

foot+="

";

return foot;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有