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、通过开始索引和结束索引查出请求页码数据,显示给前端

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值