009 批量删除
文章目录
- 前端
- 后端
https://element.eleme.cn/#/zh-CN/component/button
前端
<el-button type="danger" @click="batchDelete">批量删除</el-button>
<el-tree
ref="menuTree"
batchDelete() {
console.log("批量删除菜单...");
//封装要删除的id
let ids = [];
//通过eltree菜单 获取
let checkedNodes = this.$refs.menuTree.getCheckedNodes();
console.log("被选中的元素",checkedNodes);
for (let index = 0; index < checkedNodes.length; index++) {
//把选中的CheckBox的id值 添加到ids集合中
ids.push( checkedNodes[index].id );
}
this.$confirm(`是否批量删除[${ids}]菜单?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
this.$http({
url: this.$http.adornUrl("/product/category/delete"),
method: "post",
data: this.$http.adornData(ids, false),
}).then(({ data }) => {
this.$message({
type: "success",
message: "菜单批量删除成功!",
});
//重新刷新当前菜单
this.getMenus();
//设置需要默认展开的菜单, 设置为 要删除节点的父节点
// this.expandedKey = [node.parent.data.id];
});
})
.catch(() => {});
},
},
后端
@RestController
@RequestMapping("product/category")
public class CategoryController {
/**
* 删除
*/
@RequestMapping("/delete")
//@RequiresPermissions("product:category:delete")
public R delete(@RequestBody Integer[] ids){
//直接删除方式
//categoryService.removeByIds(Arrays.asList(ids));
//TODO 检查当前要删除的菜单,是否被别的地方引用
//逻辑删除方式
categoryService.removeMenuByIds(Arrays.asList(ids));
return R.ok();
}
}
@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {
/**
* 逻辑删除菜单
* @param asList
*/
@Override
public void removeMenuByIds(List<Integer> asList) {
//TODO 检查当前要删除的菜单是否被别的地方引用
//逻辑删除
baseMapper.deleteBatchIds(asList);
}
}
#mybatis
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: io.renren.modules.*.entity
global-config:
#数据库相关配置
db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: AUTO
logic-delete-value: -1
logic-not-delete-value: 0
banner: false
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'