標籤:enc 1.0 自測 添加 shm dex start index AC
1.在mybatis的公用mapping中添加下面設定
三層嵌套方式和用 row_number的方式都能到達效果,但是效能優劣眾說紛紜我沒親自測試過。
<?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" ><mapper namespace="common.mapping.CommonMapper"> <!-- ①採用rownum關鍵字(三層嵌套)有人說這個比下面更好 --> <sql id="Oracle_Pagination_Head"> <if test="pageIndex !=null and pageSize !=null"> <![CDATA[select y.* from(select z.*,rownum as oracleStart from (]]> </if> </sql> <sql id="Oracle_Pagination_Tail"> <if test="pageIndex != null and pageSize != null"> <![CDATA[ ) z where rownum <= (#{pageIndex}+1) * #{pageSize} ) y where y.oracleStart > #{pageIndex} * #{pageSize} ]]> </if> </sql> <!-- ②採用row_number解析函數進行分頁(效率更高) --> <!-- SELECT xx.* FROM( SELECT t.*,row_number() over(ORDER BY o_id)AS num FROM t_order t )xx WHERE num BETWEEN 5 AND 15 --> <sql id="Oracle_PageRowNuber_Head"> <if test="pageIndex !=null and pageSize !=null"> <![CDATA[SELECT xx.* FROM( SELECT t.*,row_number() over(ORDER BY order_no)AS num FROM (]]> </if> </sql> <sql id="Oracle_PageRowNuber_Tail"> <if test="pageIndex != null and pageSize != null"> <![CDATA[ )t ) xx WHERE num BETWEEN #{pageIndex} * #{pageSize} AND (#{pageIndex}+1)* {pageSize}]]> </if> </sql></mapper>
2. 後面直接引用
<select id="getListPageData" parameterType="java.util.HashMap" resultType="common.model.Row"> <include refid="common.mapping.CommonMapper.Oracle_Pagination_Head" /> select ......... <include refid="common.mapping.CommonMapper.Oracle_Pagination_Tail" /></select>
在mybatis 採用mapping檔案 中的 oracle分頁 SQL 配置在一個公用mapping中供後面引入使用