增加
1.控制层
@PostMapping("/addStudentPlus") public Result addStudentPlus(@RequestBody List<Student> student){ studnetService.addStudentPlus(student); return new Result(true, MessageConstant.ADD_CHECKGROUP_FAIL); }
2.业务层
@Override public void addStudentPlus(List<Student> student) { for (int i = 0; i < 1000; i++) { student.add(new Student((UUID.randomUUID().toString().substring(0,5)),"dada","ohdoa","dad",new Teacher("1","1","1","1"))); } studentDao.addStudentPlus(student); }
3.xml
void addStudentPlus(@Param("student") List<Student> student);
<insert id="addStudentPlus"> insert into student(id,name,address) values <foreach collection="student" separator="," item="emp" > (#{emp.id},#{emp.name},#{emp.address}) </foreach> </insert>
3.2批量增加的第二种写法
<insert id="insertBatch"> insert into dict ( id , parent_id , name , value , dict_code ) values <foreach collection="list" item="item" index="index" separator=","> ( #{item.id} , #{item.parentId} , #{item.name} , #{item.value} , #{item.dictCode} ) </foreach> </insert>
4.postman
删除
1.控制层
@PostMapping("/deleteByIds") public Result deleteByIds(String s){ Boolean flag=true; if (s.contains("-")){ flag= checkItemService.deleteByIds(Arrays.asList(s.split("-"))); }else checkItemService.deleteById(Integer.parseInt(s)); return new Result(flag,"删除成功!"); }
2.业务层
@Override public Boolean deleteByIds(List<String> asList) { return checkItemDao.deleteByIds(asList); }
3.xml
Boolean deleteByIds(@Param("asList") List<String> asList);
<delete id="deleteByIds"> delete from student <where> <foreach collection="asList" open="id in (" close=")" separator="," item="item"> #{item} </foreach> </where> </delete>
4.postman