Mybatis批量插入数据
Controller层:
Student stu=new Student(); stu.SetName("小三"); stu.SetAge(12); stu.SetSex("男"); Student stu2=new Student(); stu.SetName("小四"); stu.SetAge(13); stu.SetSex("男"); Student stu3=new Student(); stu.SetName("小五"); stu.SetAge(14); stu.SetSex("女"); List list =new ArrayList(); list.add(stu); list.add(stu2); list.add(stu3); StudentService.insert(list);
xml层:
<insert id="insertStu" parameterType="java.util.List"> insert into tb_student (name,sex,age) VALUES <foreach collection="list" item="item" index= "index" separator =","> (#{item.name}, #{item.sex},#{item.age}) </foreach> </insert>
愿你眼中有光芒,活成你想要的模样