`
hhr_michael
  • 浏览: 72661 次
  • 性别: Icon_minigender_1
  • 来自: 惠州
社区版块
存档分类
最新评论

jsp分页

阅读更多
jsp分页 (轉)
关键字: jsp分页
public class PageHelper {
//totalItem总记录数,totalPage总页数,currentPage当前页,queryString就连接地址
public static String getPageNav(int totalItem,int totalPage,int  currentPage,String queryString)
{
String pageNav="";

long totalCount=totalItem;

long currentPageNo=currentPage;

long totalPageCount=totalPage;

String regEx="(^|&)page="+currentPageNo;

if(queryString.equals(""))
{
queryString+="?page=";

}else if(!queryString.equals(""))
{
queryString=queryString.replaceAll(regEx,"");

queryString="?"+queryString+"&page=";
}
if(totalPageCount>1)
{
if(currentPageNo==1)
{
pageNav+="上一页";
}else if(currentPageNo>1)
{
pageNav+="<a href='"+queryString+(currentPageNo-1)+"'>上一页</a>";
}
}

if(totalPageCount>1 && totalPageCount<12)
{

for(int i=1;i<=totalPageCount;i++)
{
pageNav+=(currentPageNo==i)?i:"<a href='"+queryString+i+"' style='margin:5px'>"+i+"</a>";

}
}else if(totalPageCount>11)
{

if(currentPageNo<7)
{
for(int i=1;i<=currentPageNo;i++)
pageNav+=(currentPageNo==i)?i:"<a href='"+queryString+i+"' style='margin:5px'>"+i+"</a>";

for(int j=(int)currentPageNo+1;j<currentPageNo+3;j++)

pageNav+="<a href='"+queryString+j+"' style='margin:5px'>"+j+"</a>";

pageNav+="···";

for(long j=totalPageCount-3;j<=totalPageCount;j++)
{
pageNav+="<a href='"+queryString+j+"' style='margin:5px'>"+j+"</a>";
}

}else if(currentPageNo>=7)
{
for(int i=1;i<4;i++)
pageNav+="<a href='"+queryString+i+"' style='margin:5px'>"+i+"</a>";

pageNav+="···";

for(int j=(int)currentPageNo-2;j<=currentPageNo;j++)
{
pageNav+=(currentPageNo==j)?j:"<a href='"+queryString+j+"' style='margin:5px'>"+j+"</a>";
}
if(currentPageNo+3<totalPageCount)
{
for(int i=(int)currentPageNo+1;i<currentPageNo+3;i++)
{
pageNav+="<a href='"+queryString+i+"' style='margin:5px'>"+i+"</a>";
}
if(currentPageNo+6<totalPageCount)
{
pageNav+="···";

for(long j=totalPageCount-3;j<=totalPageCount;j++)
{
pageNav+="<a href='"+queryString+j+"' style='margin:5px'>"+j+"</a>";
}
}else{
for(int i=(int)currentPageNo+4;i<=totalPageCount;i++)
{
pageNav+="<a href='"+queryString+i+"' style='margin:5px'>"+i+"</a>";
}
}
}else
{
for(int i=(int)currentPageNo+1;i<=totalPageCount;i++)
{
pageNav+="<a href='"+queryString+i+"' style='margin:5px'>"+i+"</a>";
}
}

}


}
if(totalPageCount>1)
{
if(currentPageNo==totalPageCount)
{
pageNav+="下一页";
}else if(currentPageNo<totalPageCount)
{
pageNav+="<a href='"+queryString+(currentPageNo+1)+"'>下一页</a>";
}
}

// System.out.println(pageNav+"dddd");
return pageNav;
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics