文章目录
- 前端
- 后端
https://element.eleme.cn/#/zh-CN/component/button
前端
vue"> <el-button type="danger" @click="batchDelete">批量删除</el-button><el-treeref="menuTree"
vue"> batchDelete() {console.log("批量删除菜单...");//封装要删除的idlet 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*/@Overridepublic void removeMenuByIds(List<Integer> asList) {//TODO 检查当前要删除的菜单是否被别的地方引用//逻辑删除baseMapper.deleteBatchIds(asList);}
}
#mybatis
mybatis-plus:mapper-locations: classpath*:/mapper/**/*.xml#实体扫描,多个package用逗号或者分号分隔typeAliasesPackage: io.renren.modules.*.entityglobal-config:#数据库相关配置db-config:#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";id-type: AUTOlogic-delete-value: -1logic-not-delete-value: 0banner: false#原生配置configuration:map-underscore-to-camel-case: truecache-enabled: falsecall-setters-on-nulls: truejdbc-type-for-null: 'null'