基于IBATIS的自定义jsp分页标签

IBATIS中SQLSERVER和ORACLE的集合通用分页代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap     
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"     
    "
http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="QueryUtils">

 

<!-- sqlserver分页 -->
<sql id="PaginationTop">
   <isNotEmpty property="CURRENTPAGE"><isNotEmpty property="PAGESIZE">
    <![CDATA[
     SELECT TOP $PAGESIZE$ * FROM (
    ]]>
   </isNotEmpty></isNotEmpty>
</sql>

<!-- CURRENTPAGE=(PAGE-1)*PAGESIZE -->
<sql id="PaginationMid">
   <isNotEmpty property="CURRENTPAGE"><isNotEmpty property="PAGESIZE">
    <![CDATA[
     ) TEMP WHERE ID NOT IN
             (SELECT TOP $CURRENTPAGE$ ID FROM (
    ]]>
   </isNotEmpty></isNotEmpty>
</sql>

<sql id="PaginationEnd">
   <isNotEmpty property="CURRENTPAGE"><isNotEmpty property="PAGESIZE">
    <![CDATA[
     ) TEMP)
    ]]>
   </isNotEmpty></isNotEmpty>
</sql>

<!-- 排序 -->
<sql id="orderBy">
   <dynamic prepend="ORDER BY">
    <isNotEmpty prepend="," property="sortField">
     $sortField$
    </isNotEmpty>
   </dynamic>
</sql>

 

 

<!-- oracle分页 -->
<sql id="paginationStart">
   <dynamic prepend="">
    <isNotEmpty property="RowNumStart">
     <![CDATA[
       select * from(select row_.*, rownum ROWNUM_ from(
       ]]>
    </isNotEmpty>
    <isEmpty property="RowNumStart">
     <![CDATA[
      select * from(select row_.*, rownum ROWNUM_ from(
       ]]>
    </isEmpty>
   </dynamic>
</sql>

<sql id="paginationEnd">
   <dynamic prepend="">
    <isNotEmpty property="RowNumEnd">
     <![CDATA[
         )row_ where rownum<=#RowNumEnd#) where ROWNUM_ >= #RowNumStart#
        ]]>
    </isNotEmpty>
    <isEmpty property="RowNumEnd">
     <![CDATA[
       )row_ where rownum<=17) where ROWNUM_ >= 1
       ]]>
    </isEmpty>
   </dynamic>
</sql>

<!-- 排序 -->
<sql id="orderBy">
   <dynamic prepend="ORDER BY">
    <isNotEmpty prepend="," property="sortField">
     $sortField$
    </isNotEmpty>
   </dynamic>
</sql>
</sqlMap>

你可能感兴趣的:(apache,oracle,sql,jsp,ibatis)