@@ -47,11 +47,11 @@ public class MenuController {
|
|||||||
|
|
||||||
@Operation(summary = "菜单下拉列表")
|
@Operation(summary = "菜单下拉列表")
|
||||||
@GetMapping("/options")
|
@GetMapping("/options")
|
||||||
public Result<?> listMenuOptions(
|
public Result<List<Option<Long>>> listMenuOptions(
|
||||||
@Parameter(description = "是否只查询父级菜单")
|
@Parameter(description = "是否只查询父级菜单")
|
||||||
@RequestParam(required = false, defaultValue = "false") boolean onlyParent
|
@RequestParam(required = false, defaultValue = "false") boolean onlyParent
|
||||||
) {
|
) {
|
||||||
List<Option> menus = menuService.listMenuOptions(onlyParent);
|
List<Option<Long>> menus = menuService.listMenuOptions(onlyParent);
|
||||||
return Result.success(menus);
|
return Result.success(menus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public interface MenuService extends IService<Menu> {
|
|||||||
*
|
*
|
||||||
* @param onlyParent 是否只查询父级菜单
|
* @param onlyParent 是否只查询父级菜单
|
||||||
*/
|
*/
|
||||||
List<Option> listMenuOptions(boolean onlyParent);
|
List<Option<Long>> listMenuOptions(boolean onlyParent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增菜单
|
* 新增菜单
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
* @param onlyParent 是否只查询父级菜单 如果为true,排除按钮
|
* @param onlyParent 是否只查询父级菜单 如果为true,排除按钮
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Option> listMenuOptions(boolean onlyParent) {
|
public List<Option<Long>> listMenuOptions(boolean onlyParent) {
|
||||||
List<Menu> menuList = this.list(new LambdaQueryWrapper<Menu>()
|
List<Menu> menuList = this.list(new LambdaQueryWrapper<Menu>()
|
||||||
.in(onlyParent, Menu::getType, MenuTypeEnum.CATALOG.getValue(), MenuTypeEnum.MENU.getValue())
|
.in(onlyParent, Menu::getType, MenuTypeEnum.CATALOG.getValue(), MenuTypeEnum.MENU.getValue())
|
||||||
.orderByAsc(Menu::getSort)
|
.orderByAsc(Menu::getSort)
|
||||||
@@ -121,13 +121,13 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
* @param menuList 菜单列表
|
* @param menuList 菜单列表
|
||||||
* @return 菜单下拉列表
|
* @return 菜单下拉列表
|
||||||
*/
|
*/
|
||||||
private List<Option> buildMenuOptions(Long parentId, List<Menu> menuList) {
|
private List<Option<Long>> buildMenuOptions(Long parentId, List<Menu> menuList) {
|
||||||
List<Option> menuOptions = new ArrayList<>();
|
List<Option<Long>> menuOptions = new ArrayList<>();
|
||||||
|
|
||||||
for (Menu menu : menuList) {
|
for (Menu menu : menuList) {
|
||||||
if (menu.getParentId().equals(parentId)) {
|
if (menu.getParentId().equals(parentId)) {
|
||||||
Option option = new Option(menu.getId(), menu.getName());
|
Option<Long> option = new Option<>(menu.getId(), menu.getName());
|
||||||
List<Option> subMenuOptions = buildMenuOptions(menu.getId(), menuList);
|
List<Option<Long>> subMenuOptions = buildMenuOptions(menu.getId(), menuList);
|
||||||
if (!subMenuOptions.isEmpty()) {
|
if (!subMenuOptions.isEmpty()) {
|
||||||
option.setChildren(subMenuOptions);
|
option.setChildren(subMenuOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user