vue文件前端
<el-button type="warning" plain @click="handleDeletion">注 销</el-button>
// 注销
const handleDeletion = (userName) => {ElMessageBox.confirm('注销该用户所有信息后无法恢复,您确认注销吗?', '注销确认', { type: 'warning' }).then(() => {const userName = data.form.username;request.delete('http://localhost:9090/peoples/deletePeople/' + userName).then(res => {if (res.code === '200') {ElMessage.success("操作成功")router.push('/login')} else {ElMessage.error(res.msg)}})}).catch(res => {console.error('Delete request failed');})
}
springboot后台
controller
/*** 注销* @param userName*/@DeleteMapping("/deletePeople/{userName}")public Result deletePeople(@PathVariable String userName){peopleService.deletePeopleByUsername(userName);return Result.success();}
其中Result是写的一个公共方法
code是等于200(请求成功)还是500(请求失败)
mapper
//批量删除@Delete("delete from people where id in (#{id})")void deleteBatch(List<Integer> id);
service
/*** 根据用户名删除用户*/public void deletePeopleByUsername(String username) {peoplesMapper.deleteByUsername(username);}