- 代码防止
通过唯一编码在数据库获取是否存在 - 通过sql防止
insert into table (xxx) select xxx from dual where not exists(select cust_tel from crm_customer_detail_extra where cust_tel=#{custTel,jdbcType=VARCHAR})
3.注解设置防止重复提交
<insert id="insertCustDetail" parameterType="com.znlh.crm.entity.CrmCustomerDetailExtra" >
<selectKey resultType="java.lang.Integer" keyProperty="id" order="AFTER" >
SELECT LAST_INSERT_ID()
</selectKey>
insert into crm_customer_detail_extra
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="custCode != null" >
cust_code,
</if>
<if test="custAvatar != null" >
cust_avatar,
</if>
<if test="custNick != null" >
cust_nick,
</if>
<if test="logoutStatus != null" >
logout_status,
</if>
<if test="lastLogoutTime != null" >
last_logout_time,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
<if test="delFlag != null" >
del_flag,
</if>
<if test="custTel != null">
cust_tel,
</if>
</trim>
<trim prefix="select " suffix="from dual" suffixOverrides="," >
<if test="custCode != null" >
#{custCode,jdbcType=VARCHAR},
</if>
<if test="custAvatar != null" >
#{custAvatar,jdbcType=VARCHAR},
</if>
<if test="custNick != null" >
#{custNick,jdbcType=VARCHAR},
</if>
<if test="logoutStatus != null" >
#{logoutStatus,jdbcType=TINYINT},
</if>
<if test="lastLogoutTime != null" >
#{lastLogoutTime,jdbcType=TIMESTAMP},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null" >
#{delFlag,jdbcType=TINYINT},
</if>
<if test="custTel != null">
#{custTel,jdbcType=VARCHAR},
</if>
</trim>
where not exists(
select cust_tel
from crm_customer_detail_extra
where cust_tel=#{custTel,jdbcType=VARCHAR})
</insert>

1161

被折叠的 条评论
为什么被折叠?



