DIY程序分页~


function goPage(){
window.location.href='****';
}





<%=Class.pageUtil(1,3,goPage) %>




 

/**
* 分页
* @param currentPage 当前页
* @param totalPage 总页数
* @param methodName 回调方法
* @return
*/
public static String pageUtil(int currentPage,int totalPage,String methodName){
System.out.println("----");
StringBuffer sb=new StringBuffer();
sb.append("");

sb.append("
");

//最少页数
int k=1;
//最大页数
int last=1;
if(currentPage-5>0){
k=currentPage-5;
}
last=k+10;
if(k+10>totalPage){
last=totalPage;
}
sb.append("");
sb.append("首页");
sb.append("
");

for(int i=k;i if(i==currentPage){
sb.append("");
sb.append(i);
sb.append("
");
}else{
sb.append("");
sb.append(i);
sb.append("
");
}
}
if(currentPage==totalPage){
sb.append("");
sb.append("..."+totalPage);
sb.append("
");
}else{
sb.append("");
sb.append("..."+totalPage);
sb.append("
");
}
sb.append("");
}else{
sb.append("(" + (currentPage+1) + ")'>");
}
sb.append("下一页");
sb.append("
");
sb.append("
");
return sb.toString();

}

你可能感兴趣的:(java)