SpringBoot + Vue 微人事(十二)

职位批量删除实现

编写后端接口

PositionController

 @DeleteMapping("/")
    public RespBean deletePositionByIds(Integer[] ids){
        if(positionsService.deletePositionsByIds(ids)==ids.length){
            return RespBean.ok("删除成功");
        }
        return RespBean.err("删除失败");
    }

PositionsService

    public int deletePositionsByIds(Integer[] ids) {
        return positionMapper.deletePositionsByIds(ids);
    }

PositionMapper

    int deletePositionsByIds(@Param("ids") Integer[] idsInteger[] ids);

PositionMapper.xml

  delete  from position where  id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
           #{id}
         foreach>;

添加批量删除按钮
SpringBoot + Vue 微人事(十二)_第1张图片

            <el-button type="danger" size="small" style="margin-top:10px" >批量删除</el-button>

没有选中肯定默认是禁用批量删除按钮的,添加一个
SpringBoot + Vue 微人事(十二)_第2张图片
赋值就是当前选择的项
SpringBoot + Vue 微人事(十二)_第3张图片
定义一个变量,空数组变量
SpringBoot + Vue 微人事(十二)_第4张图片

   multipleSelection: []

添加一个点击事件,这个是一个点击多选框会触发的点击事件
SpringBoot + Vue 微人事(十二)_第5张图片
赋值给这个空数组变量,保存着始终点击项
SpringBoot + Vue 微人事(十二)_第6张图片
按钮禁用
SpringBoot + Vue 微人事(十二)_第7张图片

            <el-button type="danger" size="small" style="margin-top:10px" :disabled="multipleSelection.length==0">批量删除</el-button>

给这个按钮添加一个点击事件,进行连接后端,批量删除
在这里插入图片描述

<el-button type="danger" size="small" style="margin-top:10px" :disabled="multipleSelection.length==0" @click="deleteMany">批量删除</el-button>

SpringBoot + Vue 微人事(十二)_第8张图片

 deleteMany(){
                let ids ="?";
                this.multipleSelection.forEach(item=>{
                    ids += 'ids='+item.id+'&'   //ida = ?ids=  + id + &  ids=  + id + &
                })
                console.log(ids)
                this.deleteRequest("/system/basic/pos/"+ids).then(resp=>{
                    if (resp){
                        this.initPositions()
                    }
                })
            },

你可能感兴趣的:(SpringBoot,微人事,专栏,spring,boot,vue.js,后端)