mybatis存在更新不存在新增

1 主键或者唯一索引,有相同的字段进行添加时进行其他字段更新,否则进行新增

<insert id="insertFwdcBlacklist" parameterType="com.qujie.mintwo.life.fwdc.entity.FwdcBlacklist">
        insert   into fwdc_blacklist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="shopId != null">shop_id,</if>
            <if test="shopName != null">shop_name,</if>
            <if test="sdmerid != null">sdmerid,</if>
            <if test="shieldFunction != null">shield_function,</if>
            <if test="creditCode != null">credit_code,</if>
            <if test="idcard != null">idcard,</if>
            <if test="addTime != null">add_time,</if>
            <if test="addUserId != null">add_user_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateUserId != null">update_user_id,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="shopId != null">#{shopId},</if>
            <if test="shopName != null">#{shopName},</if>
            <if test="sdmerid != null">#{sdmerid},</if>
            <if test="shieldFunction != null">#{shieldFunction},</if>
            <if test="creditCode != null">#{creditCode},</if>
            <if test="idcard != null">#{idcard},</if>
            <if test="addTime != null">#{addTime},</if>
            <if test="addUserId != null">#{addUserId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
        ON DUPLICATE KEY UPDATE
        shield_function=#{shieldFunction}
    </insert>

你可能感兴趣的:(java,sql)