下面给大家介绍mybatis foreach批量插入数据:Oracle与MySQL不同点:
•主要不同点在于foreach标签内separator属性的设置问题:
•separator设置为","分割时,最终拼接的代码形式为:insert into table_name (a,b,c) values (v1,v2,v3) ,(v4,v5,v6) ,...
•separator设置为"union all"分割时,最终拼接的代码形式为:insert into table_name (a,b,c) values (v1,v2,v3) union all (v4,v5,v6) union all...
•详情请见示例代码:
Oracle:
1
2
3
4
5
6
7
8
9
10
|
< insert id= "inserData" parameterType= "com.test.aaa.Bac" > insert into table_name ( name , adress, age) values <foreach collection= "list" item= "item" index = "index" separator= "union all" > ( select #{item. name }, #{item.adress}, #{item.age} from dual ) <foreach> </ insert > |
MySQL:
1
2
3
4
5
6
7
|
< insert id= "inserData" parameterType= "com.test.aaa.Bac" > insert into table_name ( name , adress, age) values <foreach collection= "list" item= "item" index = "index" separator= "," > ( #{item. name }, #{item.adress}, #{item.age} ) <foreach> </ insert > |
总结
以上所述是小编给大家介绍的mybatis foreach批量插入数据:Oracle与MySQL区别,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!