mybatis下oracle的分页

Submitted by Lizhe on Thu, 06/08/2017 - 18:01

备忘一下分页的mapper文件

<mapper namespace="com.test">

    <sql id="paginationPrefix">
        <if test="filter != null and paginated == true">
            select * from (select rownum rn_, q_.* from (
        </if>
    </sql>

    <sql id="paginationSuffix">
        <if test="filter != null and paginated == true">
            ) q_ where rownum &lt; #{maxRowToFetch}) where rn_ &gt;= #{minRowToFetch}
        </if>
    </sql>

</mapper>

 

 

 

    <select id="findByFilter" parameterType="com.test.Filter" resultMap="searchDto">
        <include refid="com.test.paginationPrefix" />
        select * from Table
        <include refid="searchOutageFilterWhereClause" />
        ${orderByClause}
        <include refid="com.test.paginationSuffix" />
    </select>
    
    <select id="countByFilter" parameterType="com.test.Filter" resultType="int">
        select count(*) as cnt from Table
        <include refid="searchWhereClause" />
    </select>

 

    <sql id="searchOutageFilterWhereClause">
    <where>

    ....

    </where>
    </sql>