Mybatis批量删除

mybatis实现批量删除功能,前端传过来是数组,后端接收List

Controller层,service层,mapper层实现如下:


public class ArrayDTO {

    @ApiModelProperty(value = "id集合")
    private List idArray;

}

 @PostMapping(value = "/v1/batchDelete")
  @ApiOperation(value = "批量删除", notes = "根据ID删除", httpMethod = "POST")
Boolean batchDelete(@RequestBody ArrayDTO removeDto){
	 service.delete(String.join(",", removeDto.getIdArray()));
}

// service实现类
 @Override
    public void delete(String ids) {
       mapper.delete(ids.replaceAll("^|$|(?=,[^,]+?)|(?<=[^,]+?,)", "'"));
    }
    
 // mapper接口
   void delete(@Param("ids")String ids);
   
    
        delete from test where 1>2
        or id in (${ids})
    
    

你可能感兴趣的:(工作,SpringBoot)