ibtatis查询oracle分页(实例)

JSP

int totalPages = -1;//总页数

    int totalCount = 0;//总条数

    int pageNew= request.getparamter("pageNew");//当前页数

    int pageContain = 20;//每页条数

 

totalCount= selectCount();

totalPages= getAllPageNumber(totalCount,pageContain); 

 

if(pageNew<1)pageNew=1;

    if(pageNew>totalPages) pageNew=totalPages;

if(totalPages==-1) {out.print("没有符合条件的数据!"); return}

 

    <div align="center">    

         <a href="applyinfo.jsp?pageNew=1">首页</a>

         <a href="applyinfo.jsp?pageNew=<%=((pageNew-1)>1?(pageNew-1):1)%>">上一页</a>

         <a href="applyinfo.jsp?pageNew=<%=((pageNew+1)<totalPages?(pageNew+1):totalPages)%>">下一页</a>

         <a href="applyinfo.jsp?pageNew=<%=totalPages%>">末页</a><%=pageNew%>/<%=totalPages%>

    <table border="1" cellspacing="0"cellpadding="4" class="a"></div>

 

//通用计算页数函数 XXX.java

publicstaticfinalint getAllPageNumber(int allResultNumber,int pageContain)

  {

      int allPageNumber = 0;

      if(pageContain==-1)

             allPageNumber = 1;

      elseif(allResultNumber< pageContain)

             allPageNumber = 1;

      elseif(allResultNumber%pageContain!=0)

            allPageNumber = (int)allResultNumber/pageContain+ 1;

      else

            allPageNumber = (int)allResultNumber/pageContain;

      return allPageNumber;

  }

 

Ibtatis配置文件

 

<select id="select "parameterClass=" StaffApply" resultMap=" applyResultMap">

   <![CDATA[

  select two.* 

      from (select rownum rn, one.* 

            from(  

    SELECT *

     from STAFF  ]]>

      <dynamic prepend="where">

                  <isNotNull prepend="and" property="school_id">

                     SCHOOL_ID = $school_id$

                  </isNotNull>                

                </dynamic>

      <![CDATA[  )one

     ) two 

     where 1 = 1     and two.rn > 20 * ($pageNum$- 1) andtwo.rn <  20 * $pageNum$ + 1 

  

   ]]>

  </select>    

//注意,<![CDATA[   ]]>

不写可能会报错

 

//计算总页数

   <select id="countByExample"  resultClass="java.lang.Integer">

       <![CDATA[

    select count(*) from STAFF

    ]]>

  </select>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值