关于MyBatis多条件批量插入的sql语句
丶雨过天晴 2014-09-15 09:23:21 之前做的是单条数据插入多个作业(case_NO)中
#{item}是多作业的id
#{id}是查询的单条数据
<insert id="_addLoadCutBatch" parameterType="map">
insert into ST_TCSCATTROUT(
NAME,
X,
I,
CASE_NO
)
<foreach collection="caseNoList" item="item" index="index" separator="UNION ALL">
select
NAME,
X,
I,
#{item}
from ST_TCSCATTROUT T
where T.NAME||T.CASE_NO =#{id}
</insert>
现在要改成多条数据插入多条作业也就是要把#{id}换成一个list组合需要遍历一下
改成下面这样不行啊。。。俩个list遍历该怎么弄
<insert id="_addLoadCutBatch" parameterType="map">
insert into ST_TCSCATTROUT(
NAME,
X,
I,
CASE_NO
)
<foreach collection="caseNoList" item="item" index="index" separator="UNION ALL">
select
NAME,
X,
I,
#{item}
from ST_TCSCATTROUT T
where T.NAME||T.CASE_NO =#{id}
<foreach collection="nameNo" item="Nitem" index="index" open="(" separator="," close=")">
#{Nitem}
</foreach>
</foreach>
</insert>