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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 MyBatis Oracle Mapper.xml 示例: ```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.example.dao.UserDao"> <select id="getUserById" parameterType="int" resultType="com.example.entity.User"> SELECT * FROM users WHERE id = #{id} </select> <insert id="insertUser" parameterType="com.example.entity.User"> INSERT INTO users (name, age) VALUES (#{name}, #{age}) </insert> <update id="updateUser" parameterType="com.example.entity.User"> UPDATE users SET name = #{name}, age = #{age} WHERE id = #{id} </update> <delete id="deleteUser" parameterType="int"> DELETE FROM users WHERE id = #{id} </delete> </mapper> ``` 这个示例包含了四个 SQL 操作,分别是通过 `id` 获取用户信息、插入用户信息、更新用户信息和删除用户信息。这些操作都是通过 SQL 语句来实现的。 在 MyBatis 中,每个 Mapper.xml 文件都定义了一个 namespace,这个 namespace 用于在应用程序中唯一标识这个 Mapper.xml 文件对应的 DAO 接口。在这个示例中,namespace 是 `com.example.dao.UserDao`。 每个操作都有一个唯一的 `id`,这个 `id` 用于在代码中唯一标识这个操作。`parameterType` 和 `resultType` 分别表示操作的输入参数类型和输出结果类型。在这个示例中,`parameterType` 和 `resultType` 都是 Java 对象类型。 注意,这个示例中的 SQL 语句都是 Oracle 数据库的语法。如果你使用的是其他数据库,你需要根据相应的语法修改这些 SQL 语句。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值