日期:2014-05-18  浏览次数:20672 次

一百分求分页算法
一个JavaBean

分页的效果如百度或者google一样。

比如点击3的时候是:

上一页   [1]   [2]   3   [4]   [5]   [6]   [7]   [8]   [9]   [10]   [11]   [12]   下一页

点击12的时候是:

上一页   [2]   [3]   [4]   [5]   [6]   [7]   [8]   [9]   [10]   [11]   12   [13]   [14]   [15]   [16]   [17]   [18]   [19]   [20]   [21]   下一页

当前页的前后扩展后都是10页。

而超链接读到的是静态页面。

最好可以给我源码



------解决方案--------------------
int totalofpage //每页多少行
int curPage //当前页
int j; //传进来的值

StringBuffer sbp = new StringBuffer();

curPage = (int)Math.ceil((double)j/(double)totalofpage);

/*前10页*/
for(int k=10;k> =1;k--){
len=curPage-k;
if(len> 0){ sb.append( " <a href= "http://localhost:8080/_ddd.html " target=_blank> <u> "+len+ " </u> </a> &nbsp; ");
}
}

sbp.append(curPage+ "&nbsp; ");//当前页

/*后10页*/
for(int m=1;m <=10;m++){
len=curPage+m;
if(len <totalPage){
sb.append( " <a href= "http://localhost:8080/_ddd.html " target=_blank> <u> "+len+ " </u> </a> &nbsp; ");
}
}
------解决方案--------------------
http://hi.baidu.com/lael80/blog/item/74fa6ec6576d641b9d163dfd.html
下载这个论坛,里面的发布就是一样的算法

////////////bbs.rar\bbs\src\javabean\Func.java

public String ShowPage(int page_count,int page_now,String page_url){
int k=0;
String page_tmp= " ";
if(page_now> 1){
page_tmp= " <font face= 'webdings '> <a href= ' "+page_url+ "=1 ' title= '首页 '> 9 </a> </font> &nbsp; <font face= 'webdings '> <a href= ' "+page_url+ "= "+(page_now-1)+ " ' title= '上页 '> 7 </a> </font> &nbsp; ";
}else{
page_tmp= " <font face= 'webdings '> 9 </font> &nbsp; ";
page_tmp=page_tmp+ " <font face= 'webdings '> 7 </font> &nbsp; ";
}

if(page_count==1){
page_tmp=page_tmp+ "[&nbsp; ";
page_tmp=page_tmp+ "1&nbsp; ";
page_tmp=page_tmp+ "]&nbsp; ";
}
if(page_count <=10&&page_count> 1){
page_tmp=page_tmp+ "[&nbsp; ";
for(k=1;k <=page_count;k++){
if(k!=page_now)page_tmp=page_tmp+ " <a href= ' "+page_url+ "= "+k+ " '> "+k+ " </a> &nbsp; ";
else page_tmp=page_tmp+k+ "&nbsp; ";
}
page_tmp=page_tmp+ "]&nbsp; ";
}
if(page_count> 10){
if(page_now <=5){
page_tmp=page_tmp+ "[&nbsp; ";
for(k=1;k <=10;k++){
if(k!=page_now)page_tmp=page_tmp+ " <a href= ' "+page_url+ "= "+k+ " '> "+k+ " </a> &nbsp; ";
else page_tmp=page_tmp+k+ "&nbsp; ";
}
page_tmp=page_tm