mybatis配置文件詳細示例(mapper.xml),適用於所有項目的開發

<?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="com.roncoo.pay.service.notify.dao.impl.RpNotifyRecordDaoImpl" >

  <resultMap id="BaseResultMap" type="com.roncoo.pay.service.notify.entity.RpNotifyRecord" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="version" property="version" jdbcType="SMALLINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="notify_rule" property="notifyRule" jdbcType="VARCHAR" />
    <result column="edit_time" property="editTime" jdbcType="TIMESTAMP" />
    <result column="notify_times" property="notifyTimes" jdbcType="SMALLINT" />
    <result column="limit_notify_times" property="limitNotifyTimes" jdbcType="SMALLINT" />
    <result column="url" property="url" jdbcType="VARCHAR" />
    <result column="merchant_order_no" property="merchantOrderNo" jdbcType="VARCHAR" />
    <result column="merchant_no" property="merchantNo" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="SMALLINT" />
    <result column="notify_type" property="notifyType" jdbcType="SMALLINT" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, version, create_time, notify_rule, edit_time, notify_times, limit_notify_times, 
    url, merchant_order_no, merchant_no, status, notify_type
  </sql>

  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from rp_notify_record
    where id = #{id,jdbcType=VARCHAR}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from rp_notify_record
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <insert id="insert" parameterType="com.roncoo.pay.service.notify.entity.RpNotifyRecord" >
    insert into rp_notify_record (id, version, create_time, 
      notify_rule, edit_time, 
      notify_times, limit_notify_times, url, 
      merchant_order_no, merchant_no, status, 
      notify_type)
    values (#{id,jdbcType=VARCHAR}, #{version,jdbcType=SMALLINT}, #{createTime,jdbcType=TIMESTAMP}, 
      #{notifyRule,jdbcType=VARCHAR}, #{editTime,jdbcType=TIMESTAMP}, 
      #{notifyTimes,jdbcType=SMALLINT}, #{limitNotifyTimes,jdbcType=SMALLINT}, #{url,jdbcType=VARCHAR}, 
      #{merchantOrderNo,jdbcType=VARCHAR}, #{merchantNo,jdbcType=VARCHAR}, #{status,jdbcType=SMALLINT}, 
      #{notifyType,jdbcType=SMALLINT})
  </insert>

  <update id="updateByPrimaryKey" parameterType="com.roncoo.pay.service.notify.entity.RpNotifyRecord" >
    update rp_notify_record
    set version = #{version,jdbcType=SMALLINT} + 1,
      notify_rule = #{notifyRule,jdbcType=VARCHAR},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      notify_times = #{notifyTimes,jdbcType=SMALLINT},
      limit_notify_times = #{limitNotifyTimes,jdbcType=SMALLINT},
      url = #{url,jdbcType=VARCHAR},
      merchant_order_no = #{merchantOrderNo,jdbcType=VARCHAR},
      merchant_no = #{merchantNo,jdbcType=VARCHAR},
      status = #{status,jdbcType=SMALLINT},
      notify_type = #{notifyType,jdbcType=SMALLINT}
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <sql id="condition_sql">

    <if test="merchantNo != null and merchantNo != '' ">
        and merchant_no = #{merchantNo}
    </if>
    
    <if test="status != null and status != '' ">
        and status = #{status}
    </if>

    <if test="merchantOrderNo != null and merchantOrderNo != '' ">
        and merchant_order_no = #{merchantOrderNo}
    </if>

    <if test="notifyType != null and notifyType != '' ">
        and notify_type = #{notifyType}
    </if>
    
    <if test="statusNotSuccess != null and statusNotSuccess != '' ">
        and status != 'SUCCESS'
    </if>
    <if test="statusNotFailed != null and statusNotFailed != '' ">
        and status != 'FAILED'
    </if>
    <if test="maxNotifyTimes != null and maxNotifyTimes != '' ">
       <![CDATA[  and notify_times < limit_notify_times ]]>
    </if>

  </sql>
  
  <select id="listBy" parameterType="java.util.Map" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" /> from rp_notify_record
    <where>
      <include refid="condition_sql" />
    </where>
  </select>

  <select id="listPage" parameterType="java.util.Map" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" /> from rp_notify_record
    <where>
      <include refid="condition_sql" />
    </where>
    <![CDATA[ order by create_time desc limit #{pageFirst}, #{pageSize}]]>
  </select>

  <select id="listPageCount" parameterType="java.util.Map" resultType="long">
    select count(1) from  rp_notify_record
    <where>
      <include refid="condition_sql" />
    </where>
  </select>

</mapper>

 

發佈了485 篇原創文章 · 獲贊 75 · 訪問量 83萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章