SpringBoot + Vue 微人事(十二)

职位批量删除实现

编写后端接口

PositionController

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

PositionsService

java 复制代码
    public int deletePositionsByIds(Integer[] ids) {
        return positionMapper.deletePositionsByIds(ids);
    }

PositionMapper

java 复制代码
    int deletePositionsByIds(@Param("ids") Integer[] idsInteger[] ids);

PositionMapper.xml

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

添加批量删除按钮

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

没有选中肯定默认是禁用批量删除按钮的,添加一个

赋值就是当前选择的项

定义一个变量,空数组变量

bash 复制代码
   multipleSelection: []

添加一个点击事件,这个是一个点击多选框会触发的点击事件

赋值给这个空数组变量,保存着始终点击项

按钮禁用

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

给这个按钮添加一个点击事件,进行连接后端,批量删除

bash 复制代码
<el-button type="danger" size="small" style="margin-top:10px" :disabled="multipleSelection.length==0" @click="deleteMany">批量删除</el-button>
bash 复制代码
 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()
                    }
                })
            },
相关推荐
geovindu1 分钟前
rust: Chain of Responsibility Pattern (续)
开发语言·后端·设计模式·rust·责任链模式·行为模式
郝学胜-神的一滴17 分钟前
Web安全入门:读懂Web世界里的攻防
前端·网络·后端·安全·web安全·hibernate
天若有情67318 分钟前
从零搭建校园二手交易系统:Vue2 + SpringBoot 4.x 全栈实战
java·spring boot·后端
省钱兄--zs26 分钟前
碰碰好评卡系统开发实战指南 核心功能实现与部署落地全流程拆解
数据仓库·经验分享·spring boot·小程序·架构
Lost of 程序猿40 分钟前
责任链模式实战:审批流里“层层把关“的艺术
后端·设计模式·asp.net·责任链模式
知守观1 小时前
Maven SNAPSHOT 更新排查:-U 无效、clean 无用,问题在 _remote.repositories(附完整链路)
java·后端·maven
苏渡苇1 小时前
从零搭建 Vue 3 工程化项目:Vite + TypeScript + Pinia + Element Plus 实战
前端·vue.js·typescript
雪芽蓝域zzs1 小时前
第 8 节:距离测量(测距工具)
vue.js
IT_陈寒1 小时前
一文搞懂SpringBoot的核心概念
前端·人工智能·后端