{"record":{"id":"2eeddb6c7e31615a","repo":"elunez/eladmin","slug":"menu-with-title-existed","errorCode":null,"errorMessage":"Menu with title {} existed","messagePattern":"Menu with title (.+?) existed","errorType":"exception","errorClass":"EntityExistException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java","lineNumber":124,"sourceCode":"    @Override\n    public List<MenuDto> findByUser(Long currentUserId) {\n        String key = CacheKey.MENU_USER + currentUserId;\n        List<Menu> menus = redisUtils.getList(key, Menu.class);\n        if (CollUtil.isEmpty(menus)){\n            List<RoleSmallDto> roles = roleService.findByUsersId(currentUserId);\n            Set<Long> roleIds = roles.stream().map(RoleSmallDto::getId).collect(Collectors.toSet());\n            LinkedHashSet<Menu> data = menuRepository.findByRoleIdsAndTypeNot(roleIds, 2);\n            menus = new ArrayList<>(data);\n            redisUtils.set(key, menus, 1, TimeUnit.DAYS);\n        }\n        return menus.stream().map(menuMapper::toDto).collect(Collectors.toList());\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public void create(Menu resources) {\n        if(menuRepository.findByTitle(resources.getTitle()) != null){\n            throw new EntityExistException(Menu.class,\"title\",resources.getTitle());\n        }\n        if(StringUtils.isNotBlank(resources.getComponentName())){\n            if(menuRepository.findByComponentName(resources.getComponentName()) != null){\n                throw new EntityExistException(Menu.class,\"componentName\",resources.getComponentName());\n            }\n        }\n        if (Long.valueOf(0L).equals(resources.getPid())) {\n            resources.setPid(null);\n        }\n        if(resources.getIFrame()){\n            if (!(resources.getPath().toLowerCase().startsWith(HTTP_PRE)||resources.getPath().toLowerCase().startsWith(HTTPS_PRE))) {\n                throw new BadRequestException(BAD_REQUEST);\n            }\n        }\n        menuRepository.save(resources);\n        // 计算子节点数目\n        resources.setSubCount(0);\n        // 更新父节点菜单数目","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java#L106-L142","documentation":"EntityExistException thrown in MenuServiceImpl.create when a menu with the same title already exists. menuRepository.findByTitle(resources.getTitle()) is checked before save; any non-null result aborts creation. Menu titles must be globally unique across the whole menu tree, not just among siblings.","triggerScenarios":"POST /api/menus with a title that duplicates any existing menu row (e.g. a second menu named '首页' or '用户管理').","commonSituations":"Re-importing or manually re-adding a menu that already exists in another part of the tree; two developers/seed scripts adding the same menu name; copying a menu configuration between environments that already has it.","solutions":["Rename the new menu so its title is unique across all menus.","If the duplicate is unintended, delete or rename the existing menu first in Menu Management.","Check existing menus with GET /api/menus (or the lazy-load tree endpoint) before submitting to confirm the title is taken.","When seeding, make the script idempotent: skip creation when findByTitle returns a record."],"exampleFix":"// before: assumes title unique per parent\nmenuService.create(new Menu(\"用户管理\", pid));\n\n// after: guard against global title duplication\nif (menuService.findByTitle(title) == null) {\n    menuService.create(new Menu(title, pid));\n}","handlingStrategy":"validation","validationCode":"// client: check title uniqueness against loaded menu tree\nconst titles = new Set(allMenus.map(m => m.title));\nif (titles.has(form.title)) { alert('菜单标题已存在'); return; }","typeGuard":null,"tryCatchPattern":"catch (EntityExistException e) { // message contains 'Menu with title' → prompt user to pick another title }","preventionTips":["Treat menu title as globally unique when designing the form","Search existing menus before creating","Make seed scripts idempotent via findByTitle"],"tags":["eladmin","menu","duplicate","entity-exist","spring-boot"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}