淘淘商城项目补充(4)内容分类重命名和删除功能的实现

内容分类重命名和删除功能的实现

如果你需要教程的话。可以关注我的微信公众号“Java面试通关手册”,然后回复“资源分享第一波”免费领取

1,分析

更新节点名字

删除节点

代码结构

2, interface层

    E3Result upadateContentCategory(long id, String name);
    E3Result deleteContentCategory(long id);

3,service层

    /**
     * 重命名分类
     */
    @Override
    public E3Result upadateContentCategory(long id, String name) {
        // 创建一个tb_content_category表对应的pojo对象
        TbContentCategory node = contentCategoryMapper.selectByPrimaryKey(id);
        // 更新名字
        node.setName(name);
        contentCategoryMapper.updateByPrimaryKey(node);
        return null;
    }

    /**
     * 删除分类
     */
    @Override
    public E3Result deleteContentCategory(long id) {
        TbContentCategory contentCategory = contentCategoryMapper.selectByPrimaryKey(id);
        if (contentCategory.getIsParent()) {
            List<EasyUITreeNode> list = getContentCatList(id);
            // 递归删除
            for (EasyUITreeNode tbcontentCategory : list) {
                deleteContentCategory(tbcontentCategory.getId());
            }
        }
            if (getContentCatList(contentCategory.getParentId()).size() == 1) {
                TbContentCategory parentCategory = contentCategoryMapper
                        .selectByPrimaryKey(contentCategory.getParentId());
                parentCategory.setIsParent(false);
                contentCategoryMapper.updateByPrimaryKey(parentCategory);
            }
            contentCategoryMapper.deleteByPrimaryKey(id);
            return E3Result.ok();

        }

4, controller层

    @RequestMapping("/update")
    @ResponseBody
    public E3Result update(Long id, String name) {
        E3Result result = contentCategoryService.upadateContentCategory(id, name);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public E3Result update(Long id) {
        E3Result result = contentCategoryService.deleteContentCategory(id);
        return result;
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值