mybaties ON DUPLICATE KEY UPDATE IF
527
0
0
1年前
## 业务需求:数据不存在则插入,存在则更新 更新时需要判断某个字段是否为null 为null时更新
```
<insert id="insertOrupdate" parameterType="java.util.List">
insert into tbl_gold_resource(phone, job_number,customer_tag,resource_time,`type`)
values
<foreach collection="resp" item="item" index="index" separator=",">
(
#{item.custTel,jdbcType=VARCHAR},
#{item.pid,jdbcType=VARCHAR},
#{item.tagStrs,jdbcType=VARCHAR},
#{item.updateDate,jdbcType=VARCHAR},
#{item.type,jdbcType=INTEGER}
)
</foreach>
ON DUPLICATE KEY UPDATE
resource_time=IF(resource_time is null,values(resource_time),resource_time)
</insert>
```
如上 ON DUPLICATE KEY UPDATE 更新resource_time字段
IF判断即可