mybatis sql模板

<?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" >
<!--与xml对应的dao层类  -->
<mapper namespace="com.haier.show.dao.CustomerMapper" >
  <!--实体bean的字段与数据库表中字段不一致  --> 
  <resultMap id="BaseResultMap" type="com.haier.show.model.Customer" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="c_name" property="c_name" jdbcType="VARCHAR" />
    <result column="c_sex" property="c_sex" jdbcType="VARCHAR" />
    <result column="c_addr" property="c_addr" jdbcType="VARCHAR" />
    <result column="c_identity" property="c_identity" jdbcType="VARCHAR" />
    <result column="c_phone" property="c_phone" jdbcType="VARCHAR" />
    <result column="c_company_name" property="c_company_name" jdbcType="VARCHAR" />
    <result column="createdate" property="createdate" jdbcType="TIMESTAMP" />
  </resultMap>
 
  <!--sql片段  -->
  <sql id="Base_Column_List" >
    id, c_name, c_sex, c_addr, c_identity, c_phone, c_company_name, createdate
  </sql>
  
  <!--查询  -->
  <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from customer
    where id = #{id,jdbcType=INTEGER}
  </select>
  
  <!--删除  -->
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from customer
    where id = #{id,jdbcType=INTEGER}
  </delete>
 
  <!--插入  -->
  <insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="com.haier.show.model.Customer" >
    insert into customer
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="c_name != null" >
        c_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="c_name != null" >
        #{c_name,jdbcType=VARCHAR},
      </if>
      
    </trim>
  </insert>
  
  <!--修改  -->
  <update id="updateByPrimaryKeySelective" parameterType="com.haier.show.model.Customer" >
    update customer
    <set >
      <if test="c_name != null" >
        c_name = #{c_name,jdbcType=VARCHAR},
      </if>
      <if test="c_sex != null" >
        c_sex = #{c_sex,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  
</mapper>

 

转载于:https://www.cnblogs.com/SunAutumn/p/7560478.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值