Mybatis_Sql

插入集合

<insert id="insertList" parameterType="java.util.List">
    insert into operation_product_setting_attribute ( create_date, update_date,
    merchant_id, product_id, setting_id,
    name, attributes, creator,
    creator_id)
    values
    <foreach collection="list" separator="," item="item">
      (
      #{item.createDate,jdbcType=TIMESTAMP},
      #{item.updateDate,jdbcType=TIMESTAMP},
      #{item.merchantId,jdbcType=BIGINT},
      #{item.productId,jdbcType=BIGINT},
      #{item.settingId,jdbcType=BIGINT},
      #{item.name,jdbcType=VARCHAR},
      #{item.attributes,jdbcType=BIT},
      #{item.creator,jdbcType=VARCHAR},
      #{item.creatorId,jdbcType=BIGINT}
      )
    </foreach>
  </insert>

插入实体类 

<insert id="insertSelective" parameterType="com.hisun.lemon.db.entity.OperationMerchant" useGeneratedKeys="true" keyProperty="id">
        insert into operation_merchant
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="createDate != null" >
                create_date,
            </if>
            <if test="updateDate != null" >
                update_date,
            </if>
            <if test="merchantName != null" >
                merchant_name,
            </if>
            <if test="merchantCode != null" >
                merchant_code,
            </if>
            <if test="enabled != null" >
                enabled,
            </if>
            <if test="enableDelete != null" >
                enable_delete,
            </if>
            <if test="company != null" >
                company,
            </if>
            <if test="companyAddress != null" >
                company_address,
            </if>
            <if test="companyDetail != null" >
                company_detail,
            </if>
            <if test="email != null" >
                email,
            </if>
            <if test="mobile != null" >
                mobile,
            </if>
            <if test="creator != null" >
                creator,
            </if>
            <if test="creatorId != null" >
                creator_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="createDate != null" >
                #{createDate,jdbcType=TIMESTAMP},
            </if>
            <if test="updateDate != null" >
                #{updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="merchantName != null" >
                #{merchantName,jdbcType=VARCHAR},
            </if>
            <if test="merchantCode != null" >
                #{merchantCode,jdbcType=VARCHAR},
            </if>
            <if test="enabled != null" >
                #{enabled,jdbcType=BIT},
            </if>
            <if test="enableDelete != null" >
                #{enableDelete,jdbcType=BIT},
            </if>
            <if test="company != null" >
                #{company,jdbcType=VARCHAR},
            </if>
            <if test="companyAddress != null" >
                #{companyAddress,jdbcType=VARCHAR},
            </if>
            <if test="companyDetail != null" >
                #{companyDetail,jdbcType=VARCHAR},
            </if>
            <if test="email != null" >
                #{email,jdbcType=VARCHAR},
            </if>
            <if test="mobile != null" >
                #{mobile,jdbcType=VARCHAR},
            </if>
            <if test="creator != null" >
                #{creator,jdbcType=VARCHAR},
            </if>
            <if test="creatorId != null" >
                #{creatorId,jdbcType=BIGINT},
            </if>
        </trim>
    </insert>

更新实体类 

<!--更新商户信息-->
    <update id="updateByPrimaryKey" parameterType="com.hisun.lemon.db.entity.OperationMerchant" >
        update operation_merchant
        <set >
            <if test="updateDate != null" >
                update_date = #{updateDate,jdbcType=TIMESTAMP},
            </if>
            <if test="merchantName != null" >
                merchant_name = #{merchantName,jdbcType=VARCHAR},
            </if>
            <if test="merchantCode != null" >
                merchant_code = #{merchantCode,jdbcType=VARCHAR},
            </if>
            <if test="enabled != null" >
                enabled = #{enabled,jdbcType=BIT},
            </if>
            <if test="company != null" >
                company = #{company,jdbcType=VARCHAR},
            </if>
            <if test="companyAddress != null" >
                company_address = #{companyAddress,jdbcType=VARCHAR},
            </if>
            <if test="companyDetail != null" >
                company_detail = #{companyDetail,jdbcType=VARCHAR},
            </if>
            <if test="email != null" >
                email = #{email,jdbcType=VARCHAR},
            </if>
            <if test="mobile != null" >
                mobile = #{mobile,jdbcType=VARCHAR},
            </if>
            <if test="creator != null" >
                creator = #{creator,jdbcType=VARCHAR},
            </if>
            <if test="creatorId != null" >
                creator_id = #{creatorId,jdbcType=BIGINT},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值