当前位置: 代码迷 >> Web前端 >> display table 外一部分页 不支持排序
  详细解决方案

display table 外一部分页 不支持排序

热度:122   发布时间:2012-11-05 09:35:12.0
display table 外部分页 不支持排序

display table 外部分页 不支持排序

?

需求:根据当前面码数currentPage,每页记录数pageSize,数据总记录数totalCount,进行分页,算出,每页的数据开始索引startIndex和结束索引endIndex

web.xml

?

<servlet>
??? ??? <description>This is the description of my J2EE component</description>
??? ??? <display-name>This is the display name of my J2EE component</display-name>
??? ??? <servlet-name>CustomerServlet</servlet-name>
??? ??? <servlet-class>com.tht.customer.servlet.CustomerServlet</servlet-class>
??? </servlet>

??? <servlet-mapping>
??? ??? <servlet-name>CustomerServlet</servlet-name>
??? ??? <url-pattern>/servlet/CustomerServlet</url-pattern>
??? </servlet-mapping>

?

?

?

??? <jsp-config>
??? ??? <taglib>

??? ??? ??? <taglib-uri>http://jsptags.com/tags/navigation/pager</taglib-uri>

??? ??? ??? <taglib-location>/WEB-INF/pager-taglib.tld</taglib-location>

??? ??? ??? </taglib>

??? </jsp-config>

?

result.jsp ? sort="external"? 不需要

当设定 partialList="true"时,自动进行当前页排序


<%@ taglib? prefix="display" uri="http://displaytag.sf.net" %>



<head>
??? ??? ??? <link rel="stylesheet" href="<%=request.getContextPath()%>/css/print.css" type="text/css" media="print" />
??? ??? <link rel="stylesheet" href="<%=request.getContextPath()%>/css/screen.css" type="text/css" media="screen,print" />?

? </head>

<body>

??? <display:table name="list"
??? ??? ??? ??? class="its" id="item" name="list"? defaultsort="1" pagesize="${pageSize}" partialList="true" size="resultSize"? requestURI="/displaypagination/servlet/CustomerServlet">?
??? ??? ??? ?
??? ??? ??? ??? <display:column property="id"? title="I" ></display:column>
??? ??? ??? ??? <display:column property="numcuguid"? title="ID" ></display:column>
??????????????? <display:column property="vc2cuname"? title="vc2cuname" ></display:column>
??? ??? ??? ??? <display:column property="vc2cucode" title="vc2cucode"? ></display:column>
??? ??? ??? </display:table>???


<body>

?

Servlet部分

1、页面请求,会把请求的页码数传给后台:

//得到当前页的字符串
??? ??? String strP=request.getParameter((new ParamEncoder("item").encodeParameterName(TableTagParameters.PARAMETER_PAGE)));
???
??? ??? //请求的需要显示的页码数
??? ??? int currentPage=0;
??? ??? if(strP==null){
??? ??? ??? currentPage=1;
??? ??? }else{
??? ??? ??? currentPage=Integer.parseInt(strP);
??? ??? }
??? ??? //当前页
??? ??? System.out.println("currentPage:"+currentPage);


2、通过后台方式得到数据库中的总记录数:

//总记录数
??????? int totalCount=new BaseDao<CustomerServlet>().getTotalCount("select count(*) from ct_cuinfo");


3、算出开始索引和结束索引

提供参数值? int currerntPage,int pageSize,int totalCount


/**
?* oracle分页工具类
?* @author liuwen
?* 传参进来? int currerntPage,int pageSize,int totalCount
?*
?*/
public class PageTools {
???
??? int resultSize=100;? //总页数
??? int pageSize=5;//??? 每页显示的记录数
??? int totalCount=0;?? //总记录数
??? int currerntPage=0;//当前页码数
???
??? int startIndex=0;//开始记录索引
??? int endIndex=0;? //结束记录索引
???
???
??? /**
??? ?*
??? ?* @param currerntPage? 当前页码数
??? ?* @param pageSize????? 每页显示的记录条数
??? ?* @param totalCount??? 总记录数
??? ?*/
??? public PageTools(int currerntPage,int pageSize,int totalCount){
??? ??? this.currerntPage=currerntPage;
??? ??? this.pageSize=pageSize;
??? ??? this.totalCount=totalCount;
??? ??? calResultSize(); //计算总页数? 计算优先级别1
??? ??? calStartIndexAndEndIndex(); //计算开始的rownum和结束的rownum?? 计算优先级别2
??? }
???
??? /**
??? ?* 计算总页数? 计算优先级别1
??? ?*/
??? public void calResultSize(){

??? ??? int modTotal=this.totalCount%pageSize;
??? ??? if(modTotal==0){
??? ??? ??? resultSize=this.totalCount/pageSize;
??? ??? }else{
??? ??? ??? resultSize=this.totalCount/pageSize+1;
??? ??? }
??? }
??? /**
??? ?* 计算开始的rownum和结束的rownum?? 计算优先级别2
??? ?*/
??? public void calStartIndexAndEndIndex(){
??? ??? if(currerntPage==1){
??? ??? ??? startIndex=0;
??? ??? }else{
??? ??? ??? startIndex=(currerntPage-1)*pageSize;
??? ??? }
??? ???
??? ??? endIndex=currerntPage*pageSize+1;
??? ???
??? ???
??? }
???

}

?

3、通过开始索引和结束索引查出请求页码数据,显示给前端

?

  相关解决方案