首页 > 代码库 > mybatis-oracle(ssi2框架) 批量增加
mybatis-oracle(ssi2框架) 批量增加
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
本文出自 “大话程序” 博客,请务必保留此出处http://houqida.blog.51cto.com/8877896/1562410
mybatis-oracle(ssi2框架) 批量增加
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。