mybatis批量添加、批量删除

<!-- 批量添加 -->
<insert id="insertNameListSynHisBatch" parameterType="java.util.List" useGeneratedKeys="false">
insert into tb_namelist_syn_his (SERIAL, RECORDNUMBER, HASHTBNAME,
CTLTYPE, SOURCE, CREATETIME,
CKEY, CVALUE)
<foreach collection="list" item="his" index="index" separator=" union all ">
(
SELECT #{his.serial,jdbcType=VARCHAR},
#{his.recordnumber,jdbcType=VARCHAR},
#{his.hashtbname,jdbcType=VARCHAR},
#{his.ctltype,jdbcType=VARCHAR},
#{his.source,jdbcType=INTEGER},
#{his.createtime,jdbcType=DATE},
#{his.ckey,jdbcType=VARCHAR},
#{his.cvalue,jdbcType=VARCHAR}
FROM DUAL
)
</foreach>
</insert>
<!-- 批量删除 -->
<delete id="deleteNameListSynHisBatch" parameterType="java.util.List">
delete from tb_namelist_syn A
where exists
(
select 1 from(
<foreach collection="list" item="item" index="index" separator="union all">
select B.* from tb_namelist_syn B where 1=1 and B.serial=#{item.serial,jdbcType=VARCHAR}
</foreach>
)S where A.serial=S.serial
)
</delete>

如果不用@param系统默认list

猜你喜欢

转载自www.cnblogs.com/stormy/p/9218467.html