1.student类
package com.test.hou.po; public class Student { private int sid; private String sname; private int sage; public int getSid() { return sid; } public void setSid(int sid) { this.sid = sid; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public int getSage() { return sage; } public void setSage(int sage) { this.sage = sage; } }
2.StudentAction
public String batchInsertStudent(){ List<Student> studentslist=new ArrayList<Student>(); for (int i = 0; i < 10; i++) { Student student=new Student(); student.setSid(i); student.setSname("aa"+i); student.setSage(i+10); studentslist.add(student); } studentService.batchInsertStudent(studentslist); return "batchinsertstudent"; }
3.studentMapper.xml
<insert id="batchInsertStudent" parameterType="java.util.List"> insert into student <foreach collection="list" separator="union all" item="item" index="index"> (select #{item.sid},#{item.sname},#{item.sage} from dual ) </foreach> </insert>
注意:此处sql没有values, separator 为union all和select ----from dual
1.传递单参数且为list集合,collection 为list
2.传单参数且为数组,collection为array
3.传多参数且为map,collectin 为map的key
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。