关于mybatis中对mysql和Oracle数据库分页插件的使用

首先是Oracle数据库:在mybatis相对应的mapper.xml文件里:

<sql id="OracleDialectPrefix">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 16:41:13 CST 2017.
    -->
    <if test="page != null">
      select * from ( select row_.*, rownum rownum_ from ( 
    </if>
  </sql>
  <sql id="OracleDialectSuffix">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Nov 30 16:41:13 CST 2017.
    -->
    <if test="page != null">
      <![CDATA[ ) row_ ) where rownum_ > #{page.startRow} and rownum_ <= #{page.startRow} + #{page.pageSize} ]]>
    </if>
  </sql>
在Oracle数据库中要有两条sql包着的分页语句,然后具体用的时候:

 <select id="selectByExampleForCamera" parameterType="com.vrview.ssm.model.example.DeviceExample" resultMap="ResultMapForCamera">
    <include refid="OracleDialectPrefix" />
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from CFG_DEVICE
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <include refid="OracleDialectSuffix" />
  </select>
要在查询语句一前一后。

2、再看msql的分页

分页代码:

<sql id="MysqlDialectSuffix">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Jun 14 15:39:27 CST 2017.
    -->
    <if test="page != null">
      <![CDATA[ limit #{page.startRow},#{page.pageSize} ]]>
    </if>
  </sql>
用到语句中:
<select id="selectByExampleWithPolicy" parameterType="cn.vrview.sa.model.example.LevDeviceExample" resultMap="BaseResultWithPolicyMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from LEV_DEVICE
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <include refid="MysqlDialectSuffix" />
  </select>
只要放在select语句句末就行。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值