Oracle Paging SQL configuration in MyBatis with mapping files is used in a common mapping for later ingestion

Source: Internet
Author: User

1. Add the following settings in the MyBatis public mapping

Three layers of nesting and using row_number can reach the effect, but the performance of the pros and cons I have not personally tested.

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd "><Mappernamespace= "Common.mapping.CommonMapper">    <!--① using rownum keyword (three-layer nesting) someone says this is better than the bottom. -    <SQLID= "Oracle_pagination_head">        <ifTest= "PageIndex!=null and PageSize!=null">            <! [Cdata[Select Y.* from (select Z.*,rownum as Oraclestart from (]]>        </if>    </SQL>    <SQLID= "Oracle_pagination_tail">        <ifTest= "PageIndex! = null and PageSize! = NULL">            <! [Cdata[) Z where rownum <= (#{pageindex}+1) * #{pagesize}) y where Y.oraclestart > #{pageindex} * #{pagesize}]]>        </if>    </SQL>    <!--② using Row_number analytic functions for paging (higher efficiency) -    <!--Select xx.* from (select T.*,row_number () over (ORDER by o_id) as Num from T_order t) xx WHERE num between 5 an D -    <SQLID= "Oracle_pagerownuber_head">        <ifTest= "PageIndex!=null and PageSize!=null">            <! [Cdata[Select xx.* from (select T.*,row_number () over (ORDER by order_no) as Num from (]]>        </if>    </SQL>    <SQLID= "Oracle_pagerownuber_tail">        <ifTest= "PageIndex! = null and PageSize! = NULL">            <! [Cdata[) t) xx WHERE num between #{pageindex} * #{pagesize} and (#{pageindex}+1) * {pageSize}]]>        </if>    </SQL></Mapper>

2. Following the direct reference

<SelectID= "Getlistpagedata"ParameterType= "Java.util.HashMap"Resulttype= "Common.model.Row">        <includerefID= "Common.mapping.CommonMapper.Oracle_Pagination_Head" />Select ... ..<includerefID= "Common.mapping.CommonMapper.Oracle_Pagination_Tail" /></Select>

Oracle Paging SQL configuration in MyBatis with mapping files is used in a common mapping for later ingestion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.