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

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

1,分析

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

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

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

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;
    }

相关文章:

  • 2021-10-13
  • 2021-09-17
  • 2021-11-18
  • 2021-05-18
  • 2021-11-14
  • 2021-11-22
  • 2021-09-25
  • 2021-10-15
猜你喜欢
  • 2021-07-28
  • 2021-12-15
  • 2018-11-11
  • 2021-06-17
  • 2021-12-27
  • 2021-09-17
  • 2021-10-18
相关资源
相似解决方案