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'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

简 洁 冬冬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值