- 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 batchUpdateStudent(){ List<Student> studentslist=new ArrayList<Student>(); for (int i = 0; i < 10; i++) { Student student=new Student(); student.setSid(i); student.setSname("cc"+i); student.setSage(i+10); studentslist.add(student); } studentService.batchUpdateStudent(studentslist); return "batchinsertstudent"; }
3.
<update id="batchUpdateStudent" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" separator="" open="begin" close="end;" > update student set sname =#{item.sname}, sage =#{item.sage} where sid =#{item.sid}; </foreach> </update>
注意:oracle批量更新 open="begin" end="end;" sql最后为分号
时间: 2024-11-02 01:10:12