批量增加和批量删除

增加

1.控制层

@PostMapping("/addStudentPlus")
public Result addStudentPlus(@RequestBody List student){
    studnetService.addStudentPlus(student);
    return new Result(true, MessageConstant.ADD_CHECKGROUP_FAIL);
}

批量增加和批量删除_第1张图片

2.业务层

@Override
public void addStudentPlus(List 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);

    insert into student(id,name,address)
    values
    
        (#{emp.id},#{emp.name},#{emp.address})
    

批量增加和批量删除_第2张图片

3.2批量增加的第二种写法

批量增加和批量删除_第3张图片


    insert into dict (
        id ,
        parent_id ,
        name ,
        value ,
        dict_code
    ) values
    
        (
        #{item.id} ,
        #{item.parentId} ,
        #{item.name} ,
        #{item.value} ,
        #{item.dictCode}
        )
    

 

4.postman

批量增加和批量删除_第4张图片

删除

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,"删除成功!");
}

批量增加和批量删除_第5张图片

2.业务层

@Override
public Boolean deleteByIds(List asList) {
    return checkItemDao.deleteByIds(asList);
}

3.xml

Boolean deleteByIds(@Param("asList") List asList);

    delete from student
    
    
        #{item}
    
 

批量增加和批量删除_第6张图片

4.postman 

批量增加和批量删除_第7张图片

你可能感兴趣的:(mysql,java-ee)