zoukankan      html  css  js  c++  java
  • 淘淘商城项目补充(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;
        }
  • 相关阅读:
    并不对劲的bzoj3932: [CQOI2015]任务查询系统
    并不对劲的bzoj4868: [Shoi2017]期末考试
    并不对劲的bzoj1853:[SCOI2010]幸运数字
    并不对劲的bzoj4199: [Noi2015]品酒大会
    并不对劲的bzoj1500: [NOI2005]维修数列
    并不对劲的hdu4777
    并不对劲的线段树套平衡树
    44.Linked List Cycle II(环的入口节点)
    43.Word Break(看字符串是否由词典中的单词组成)
    42.Flatten Binary Tree to Linked List
  • 原文地址:https://www.cnblogs.com/snailclimb/p/9086353.html
Copyright © 2011-2022 走看看