问题描述
请提供具体的代码。谢了!邮箱:huqike5@126.com
解决方案
解决方案二:
写个自定义标签吧!给你个例子,前端:<fn:pageurl="/profile/allQuestionAndAnswer?userId=${userId}"></fn:page>,后端:privatestaticfinallongserialVersionUID=-1885082542634459990L;privatestaticfinalStringPAGE_FIRST_DIV="<divclass="pagelist">";privatestaticfinalStringPAGE_END_DIV="</div>";privatestaticfinalintPAGE_BETWEEN_SIZE=4;//当前页的前后页数间距privatestaticfinalintPAGE_FIRST_LAST_BETWEEN_SIZE=2;privateStringurl;privateStringpageName="entityPage";publicStringgetPageName(){returnpageName;}publicvoidsetPageName(StringpageName){this.pageName=pageName;}publicStringgetUrl(){returnurl;}publicvoidsetUrl(Stringurl){this.url=url;}@OverridepublicintdoStartTag()throwsJspException{StringBufferpageSb=newStringBuffer();Objectobj=RequestUtils.getRequest().getAttribute(pageName);intcurPage=1;inttotalPage=1;if(obj!=null){if(objinstanceofEntityPage){EntityPageentityPage=(EntityPage)obj;curPage=entityPage.getCurrentPage();totalPage=entityPage.getPageCount();}elseif(objinstanceofFnEntityPage){FnEntityPageentityPage=(FnEntityPage)obj;curPage=entityPage.getCurrentPage();totalPage=entityPage.getPageCount();}}if(obj!=null&&totalPage>1){pageSb.append(PAGE_FIRST_DIV);//上一页if(curPage==1){pageSb.append("<spanclass="disabled">上一页</span>");}else{Stringparam=""+(curPage-1);pageSb.append("<ahref=""+"javascript:page('"+param+"')">上一页</a>");}intbeginPage=curPage-PAGE_BETWEEN_SIZE;intendPage=curPage+PAGE_BETWEEN_SIZE;if(endPage>totalPage){endPage=totalPage;}if(beginPage<1){beginPage=1;}//如果beginPage>2if(beginPage>PAGE_FIRST_LAST_BETWEEN_SIZE){StringfirstParam=""+1;pageSb.append("<ahref=""+"javascript:page('"+firstParam+"')">"+1+"</a>");StringsecondParam=""+2;pageSb.append("<ahref=""+"javascript:page('"+secondParam+"')">"+2+"</a>");pageSb.append("...");}for(inti=beginPage;i<=endPage;i++){if(curPage==i){pageSb.append("<spanclass="current">"+i+"</span>");}else{Stringparam=""+i;pageSb.append("<ahref=""+"javascript:page('"+param+"')">"+i+"</a>");}}if(endPage<(totalPage-1)){StringfirstParam=""+(totalPage-1);pageSb.append("...<ahref=""+"javascript:page('"+firstParam+"')">"+(totalPage-1)+"</a>");StringsecondParam=""+(totalPage);pageSb.append("<ahref=""+"javascript:page('"+secondParam+"')">"+(totalPage)+"</a>");}//下一页if(curPage==totalPage){pageSb.append("<spanclass="disabled">下一页</span>");}else{Stringparam=""+(curPage+1);pageSb.append("<ahref=""+"javascript:page('"+param+"')">下一页</a>");}//处理分页请求pageSb.append("<scripttype="text/javascript">");pageSb.append("functionpage(curPage){");pageSb.append("varpageform=document.getElementById('pageform');");pageSb.append("document.getElementById("pc.currentPage").value=curPage;");pageSb.append("pageform.submit();");pageSb.append("}");pageSb.append("</script>");pageSb.append(PAGE_END_DIV);}JspWriterout=pageContext.getOut();try{out.print(pageSb.toString());}catch(IOExceptione){e.printStackTrace();}returnTag.SKIP_BODY;}
解决方案三:
前面的数字固定死了,把当前的页数提交到相应的servlet或者action,大于10的页数就通过点击一次下一页,当前页数+1,提交过去