mysql批量插入,批量更新

时间:2023-03-10 04:02:02
mysql批量插入,批量更新

进行批量操作的时候,一定要事先判断数组非空

<insert id="batchInsert"parameterType="java.util.List">
insert into DATA (ID, TEXT, STAUTS)
<foreach close=")"collection="list"item="item"index="index"open="("separator="union">
select
#{item.id,jdbcType=VARCHAR},
#{item.text,jdbcType=VARCHAR},
#{item.stauts,jdbcType=VARCHAR}
from dual
</foreach>
</insert>
AND r.license_plate IN
<foreach collection="rdRiskEventInfoList" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>

  

update rd_risk_event_info SET truck_risk_id=#{id, jdbcType=VARCHAR} where id in
<foreach item="item" index="index" collection="idList" open="("
separator="," close=")">
#{item.id}
</foreach>