Mybatis-plus批量删除

        

实体类

package com.baizhi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 

* InnoDB free: 11264 kB *

* * @author 狂神 * @since 2021-06-22 */ @Data @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @ApiModel(value="User对象", description="InnoDB free: 11264 kB") public class User implements Serializable { private static final long serialVersionUID=1L; @ApiModelProperty(value = "主键ID") @TableId(value = "id", type = IdType.ID_WORKER) private Long id; @ApiModelProperty(value = "姓名") private String name; @ApiModelProperty(value = "年龄") private Integer age; @ApiModelProperty(value = "邮箱") private String email; }

 集合类

package com.baizhi.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserList{
     private List ids;
}

service

  String deleteIds(UserList userList);
ServiceImpl
 @Override
    public String deleteIds(UserList userList) {
        List ids = userList.getIds();
        if (!ids .isEmpty()&&ids.size()==0) {
          return "没有数据";
        }else{
            QueryWrapper wrapper = new QueryWrapper<>();
            wrapper.in("id",ids);
            userMapper.delete(wrapper);
        }
        return "删除成功";
    }

controller

  @DeleteMapping("/delete")
    public String delete(@RequestBody UserList userList) {
        userService.deleteIds(userList);
        return "删除成功";
    }

你可能感兴趣的:(java)