网上找了一下,大体就三种实现方法,代码直接照搬都有问题,
现在先放我自己试过的没有问题的方法:
Mybatis代码:
<insert id="add" parameterType="java.util.List">
insert into GROUP_INFO( group_id , group_name )
select group_id , group_name
from (
<foreach collection="list" item="item" separator=" union ">
<![CDATA[
select #{item.groupId} as group_id ,
#{item.groupName} as group_name from dual ]]>
</foreach>
)
</insert>
dao层Java接口代码:
public Integer add(List<GroupInfo> list);
我不知道是不是版本的不同,有人用insert标签可以和iterate标签组合,但是我这边insert标签里面套用iterate标签就会报错,提示insert标签中可使用的的标签不包括 iterate,主要报错提示如下:
Multiple annotations found at this line:
- The content of element type “insert” must match “(selectKey|include|trim|where|set|foreach|choose|if|bind)”.
还有就是parameterClass 和parameterType,我这边只支持parameterType,不支持parameterClass,找不到parameterClass 这个属性 。