1.student类package com.test.hou.po; public class Student { private int s
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
--结束END--
本文标题: mybatis-oracle(ssi2框架) 批量增加
本文链接: https://lsjlt.com/news/42995.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0