Mybatis-plus批量删除

时间:2025-04-01 13:12:13

        

实体类

package ;

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

import ;

/**
 * <p>
 * InnoDB free: 11264 kB
 * </p>
 *
 * @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 ;

import ;
import ;
import ;

import ;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserList{
     private List<Long> ids;
}

service

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

controller

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