fix(system): 修复新增菜单时上级菜单不存在的检查
- 在 MenuDto 中将 pid 字段默认值设为 null,确保在新增根菜单时 pid 为 null- 在 MenuServiceImpl 中添加对上级菜单不存在的检查,避免创建无效的菜单项
This commit is contained in:
parent
6e9e674a91
commit
1f6d9310b3
@ -16,7 +16,7 @@ public class MenuDto {
|
||||
/**
|
||||
* 父菜单ID
|
||||
*/
|
||||
private Long pid;
|
||||
private Long pid = null;
|
||||
/**
|
||||
* 菜单类型
|
||||
*/
|
||||
|
@ -48,6 +48,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuRepository, Menu> implement
|
||||
if (baseMapper.exists(new LambdaQueryWrapper<Menu>().eq(Menu::getPermissions, dto.getPermissions()))) {
|
||||
throw new ConstraintException("该权限已存在!请检查输入表单是否出错!");
|
||||
}
|
||||
if (baseMapper.selectOne(new LambdaQueryWrapper<Menu>().eq(Menu::getPid, dto.getPid())) == null && dto.getPid() != null) {
|
||||
throw new ConstraintException("上级菜单不存在!请检查输入表单是否出错!");
|
||||
}
|
||||
Menu menu = mapper.toEntity(dto);
|
||||
baseMapper.insert(menu);
|
||||
return menu;
|
||||
|
Loading…
Reference in New Issue
Block a user