问题描述
分页我知道也可以用自定义标签来做无奈学的太烂了只好用sql来做看网上有人写出了sql语句但我不知道放在哪里怎么用(好吧我是小白)最好2个都教我怎么用说的尽量详细点哈一定要有例子理论太空洞了还有就是这2种我知道的分页哪种效率更高一点或者说企业里面哪种用的更为广泛
解决方案
解决方案二:
分页Bean:PageBean.javapackagecom.accp.bookstore.pagination;importjava.util.Enumeration;importjava.util.HashMap;importjava.util.Map;importjavax.servlet.http.HttpServletRequest;/***分页JavaBean***/publicclassPageBean{/*当前页*/privateintcurPage=1;/*总记录数*/privateinttotalRecord=0;/*每页记录数*/privateintpageRecord=10;/*是否分页,默认分页*/privatebooleanpaginate=true;/*用来存放其它查询参数*/privateMap<String,String[]>parameters=newHashMap<String,String[]>();publicPageBean(){super();}publicPageBean(HttpServletRequestrequest){super();StringpageRecord=request.getParameter("pageRecord");StringcurPage=request.getParameter("curPage");Stringpaginate=request.getParameter("paginate");//将请求中的所有参数保存这个Map集合中Enumeratione=request.getParameterNames();StringparamName=null;String[]paramValues=null;while(e.hasMoreElements()){paramName=(String)e.nextElement();paramValues=request.getParameterValues(paramName);parameters.put(paramName,paramValues);}this.setPageRecord(pageRecord);this.setCurPage(curPage);this.setPaginate(paginate);}publicMap<String,String[]>getParameters(){returnparameters;}publicintgetCurPage(){returncurPage;}publicvoidsetCurPage(intcurPage){if(curPage>1){this.curPage=curPage;}}publicvoidsetCurPage(StringcurPage){if(null==curPage||curPage.trim().equals("")){return;}intacurPage=Integer.parseInt(curPage);this.setCurPage(acurPage);}publicintgetPageRecord(){returnpageRecord;}publicvoidsetPageRecord(intpageRecord){this.pageRecord=pageRecord;}publicvoidsetPageRecord(StringpageRecord){if(null!=pageRecord&&!pageRecord.trim().equals("")){this.pageRecord=Integer.parseInt(pageRecord);}}publicintgetTotalRecord(){returntotalRecord;}publicvoidsetTotalRecord(inttotalRecord){this.totalRecord=totalRecord;}/***true表示进行分页**@return*/publicbooleanisPaginate(){returnpaginate;}/***设置是否分页true分页,false不分页**@parampaginate*/publicvoidsetPaginate(booleanpaginate){this.paginate=paginate;}/***设置是否分页true分页,false不分页**@parampaginate*/publicvoidsetPaginate(Stringpaginate){if(null!=paginate&&paginate.trim().equalsIgnoreCase("false")){this.setPaginate(false);}else{this.setPaginate(true);}}/***返回下一页页码**@return*/publicintgetNextPageNumber(){intnextPageNumber=this.curPage+1;if(nextPageNumber>this.getMaxPageNumber()){nextPageNumber=this.getMaxPageNumber();}returnnextPageNumber;}/***返回上一页页码**@return*/publicintgetPreviousPageNumber(){intpreviousPageNumber=this.curPage-1;if(previousPageNumber<1){previousPageNumber=1;}returnpreviousPageNumber;}/***返回最大页码编号**@return*/publicintgetMaxPageNumber(){intmaxPageNumber=1;if(this.totalRecord>this.pageRecord){if(0==this.totalRecord%this.pageRecord){maxPageNumber=this.totalRecord/this.pageRecord;}else{maxPageNumber=this.totalRecord/this.pageRecord+1;}}returnmaxPageNumber;}/***获取起始记录下标**@return*/publicintgetStartRecordIndex(){returnthis.pageRecord*(this.curPage-1);}publicbooleanisEnabled(){booleanb=true;if(!this.isPaginate()||this.getTotalRecord()<this.getPageRecord()){b=false;}returnb;}publicStringtoString(){StringBufferbf=newStringBuffer();bf.append("curPage="+curPage);bf.append(",totalRecord="+totalRecord);bf.append(",pageRecord="+pageRecord);returnbf.toString();}}
标签类编写:PageBeanTag.javapackagecom.accp.news.tag;importjavax.servlet.jsp.JspException;importjavax.servlet.jsp.tagext.BodyTagSupport;importcom.accp.news.util.PageBean;/***通用分页标签**/publicclassPageBeanTagextendsBodyTagSupport{privatestaticfinallongserialVersionUID=8450962461296575662L;/*分页JavaBean*/privatePageBeanpageBean=null;/*查询条件*/privateStringurl=null;publicPageBeanTag(){super();}publicPageBeangetPageBean(){returnpageBean;}publicvoidsetPageBean(PageBeanpageBean){this.pageBean=pageBean;}publicStringgetUrl(){returnurl;}publicvoidsetUrl(Stringurl){this.url=url;}@OverridepublicintdoStartTag()throwsJspException{if(null!=pageBean){try{pageContext.getOut().write(getHTML());}catch(Exceptionex){ex.printStackTrace();thrownewRuntimeException(ex);}}returnSKIP_BODY;}/*将分页JavaBean转换成HTML字符串*/privateStringgetHTML(){StringBufferbf=newStringBuffer();bf.append("每页"+pageBean.getPageRecord()+"行");bf.append("共"+pageBean.getTotalRecord()+"行");bf.append("第"+pageBean.getCurPage()+"页");bf.append("共"+pageBean.getMaxPageNumber()+"页");bf.append("<ahref='javascript:gotoPage("+1+")'>首页</a>");bf.append("<ahref='javascript:gotoPage("+pageBean.getPreviousPageNumber()+")'>上一页</a>");bf.append("<ahref='javascript:gotoPage("+pageBean.getNextPageNumber()+")'>下一页</a>");bf.append("<ahref='javascript:gotoPage("+pageBean.getMaxPageNumber()+")'>尾页</a>");bf.append("页数<inputtype='text'id='pageNumber'style='width:20px;'/><ahref='javascript:jumpPage("+pageBean.getMaxPageNumber()+")'>GO</a>");//拼接查询字符串,当前页作为最后一个条件if(-1==this.url.lastIndexOf("?")){this.url+="?curPage=";}else{this.url+="&curPage=";}//分页所需JS方法和变量bf.append("<script>");bf.append("varurl='"+url+"';");bf.append("functiongotoPage(curPage){vars=url+curPage;location.href=s;}");bf.append("varmaxPageNumber="+pageBean.getMaxPageNumber()+";");bf.append("functionjumpPage(){varcurPage=document.getElementById('pageNumber').value;if(curPage==''||isNaN(curPage)||parseInt(curPage)<1||parseInt(curPage)>maxPageNumber){alert('请输入一个正确的页码');return;}gotoPage(curPage);}");bf.append("</script>");returnbf.toString();}}
标签定义:pageBean.tld<!DOCTYPEtaglibPUBLIC"-//SunMicrosystems,Inc.//DTDJSPTagLibrary1.2//EN""http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"><taglibxmlns="http://java.sun.com/JSP/TagLibraryDescriptor"><tlib-version>1.0</tlib-version><jsp-version>1.2</jsp-version><short-name>SimpleTags</short-name><tag><name>pageBean</name><tag-class>com.accp.news.tag.PageBeanTag</tag-class><body-content>empty</body-content><attribute><name>url</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute><attribute><name>pageBean</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute></tag></taglib>
解决方案三:
自己的帖子自己顶
解决方案四:
数据量小就用标签分页,数据量大就用SQL分页
解决方案五:
还有吗大家帮帮我啊
解决方案六:
mysql用limit,oracle用rowid
解决方案七:
5L同学我用的是MSSQL
解决方案八:
该回复于2010-12-07 09:17:29被版主删除
解决方案九:
连用的什么数据库都不说!对于这种不明不白的问题,我建议不要再进行回复
解决方案十:
sqlserver的飘过.
解决方案十一:
我也不是很清楚的···
解决方案十二:
用标签很好的啊。displaytable啊test这个对象模型就不说了CTRL中这样EntityQueryquery=newEntityQuery(Test.class,"test");MultiPageForHqlmph=this.getMultiPageFactory().createMultiPageForHql(query);mp.put("tests",mph);jsp中<display:tablename="tests"id="test"requestURI="test.do"><display:columntitle="名字"property="name"/></display:table>很方便的啊
解决方案十三:
mysql用limit,oracle用rowid
解决方案十四:
mssqllimitoraclerownumsqlservertopmysql:select*fromt_userlimit0,5;sqlserver:selecttoppageSize*fromt_userwhereidnotin(selectidformt_userwhereid<=(pageNo-1)*pageSize);oracle:selecty.*,y.rnfrom(selectt.*,rownumrnfrom(select*fromt_user)twhererownum<=5)ywherey.rn>0希望对楼主有用.一般分页都会写一个分页组件的
解决方案十五:
$maxRows_show_campaign=20;$pageNum_show_campaign=0;........//提供部分代码;<divid="lantiao_2">共有<?phpecho($totalRows_show_campaign);?>条记录<?phpecho$maxRows_show_campaign;?>条/页第<?phpecho$pageNum_show_campaign+1;?>/<?phpechoceil($totalRows_show_campaign/20);?>页<?phpif($pageNum_show_campaign>0){//Showifnotfirstpage?><ahref="<?phpprintf("%s?pageNum_show_campaign=%d%s",$currentPage,0,$queryString_show_campaign);?>">首页</a><ahref="<?phpprintf("%s?pageNum_show_campaign=%d%s",$currentPage,max(0,$pageNum_show_campaign-1),$queryString_show_campaign);?>">上一页</a><?php}//Showifnotfirstpageelse{echo"首页上一页";}?><?phpif($pageNum_show_campaign<$totalPages_show_campaign){//Showifnotlastpage?><ahref="<?phpprintf("%s?pageNum_show_campaign=%d%s",$currentPage,min($totalPages_show_campaign,$pageNum_show_campaign+1),$queryString_show_campaign);?>">下一页</a><ahref="<?phpprintf("%s?pageNum_show_campaign=%d%s",$currentPage,$totalPages_show_campaign,$queryString_show_campaign);?>">尾页</a><?php}//Showifnotlastpageelse{echo"下一页尾页";}?></div>