<insert id="insertCompanyMegBase" useGeneratedKeys="true" keyProperty="id" parameterType="com.sptit.isv.pojo.db1.DevCompanyMegBase">
<selectKey keyProperty="count" resultType="java.lang.Integer" order="BEFORE">
SELECT COUNT(*) as count FROM company_meg_base WHERE apply_id = #{applyId} AND type = #{type}
</selectKey>
<!--如果不存在创建 -->
<if test="count==0">
INSERT INTO company_meg_base
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="editTime != null" >
edit_time ,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="editTime != null" >
#{editTime,jdbcType=TIMESTAMP},
</if>
</trim>
</if>
<!--如果存在更新 -->
<if test="count > 0">
UPDATE company_meg_base
<set>
<if test="editTime != null" >
edit_time = #{editTime,jdbcType=TIMESTAMP},
</if>
</set>
WHERE apply_id = #{applyId} AND type = #{type}
</if>
</insert>
SQL不存在创建,存在更新
最新推荐文章于 2022-10-11 13:27:13 发布