标签:list() list getmenu 管理 equals col child submenu ryu
@GetMapping("/menu/tree") @Timed public ResponseEntity<List<MenuInfo>> getMenuTree() { List<MenuInfo> list = new ArrayList(); HashMap<String,Object> result = new HashMap<String,Object>(); List<MenuEntity> menulist = menuMapper.getAll(); if(menulist!=null) { DozerBeanMapper mapper = new DozerBeanMapper(); for (MenuEntity menu : menulist) { if(StringUtils.isEmpty(menu.getParentMenuId())) { MenuInfo mi = (MenuInfo) mapper.map(menu, MenuInfo.class); list.add(mi); addSubMenu(mi, menulist); } } } HttpHeaders httpHeaders = new HttpHeaders(); return new ResponseEntity<>(list, httpHeaders, HttpStatus.OK); } private void addSubMenu(MenuInfo mi,List<MenuEntity> menulist){ if(menulist!=null&& menulist.size()>0){ List<MenuEntity> submenus = menulist.stream().filter(s->s.getParentMenuId()!=null && s.getParentMenuId().equals(mi.getMenuId())).collect(Collectors.toList()); if(submenus!=null &&submenus.size()>0){ DozerBeanMapper mapper = new DozerBeanMapper(); mi.subMenu = new ArrayList(); for (MenuEntity childmenu : submenus){ MenuInfo child = (MenuInfo) mapper.map(childmenu, MenuInfo.class); mi.subMenu.add(child); addSubMenu(child, menulist); } } } } //获取三层页面 @GetMapping("/menu/getmenulist") @Timed public JsonResult queryUserRole(){ List<MenuInfo> list = new ArrayList(); UserEntity user = userService.getUserWithAuthorities(); List<MenuEntity> menulist = menuMapper.getThreeMenuByUserId(user.getUserId());; if(menulist!=null) { DozerBeanMapper mapper = new DozerBeanMapper(); for (MenuEntity menu : menulist) { if(StringUtils.isEmpty(menu.getParentMenuId())) { MenuInfo mi = (MenuInfo) mapper.map(menu, MenuInfo.class); list.add(mi); addSubMenu(mi, menulist); } } } return new JsonResult(list,true,"0",""); }
标签:list() list getmenu 管理 equals col child submenu ryu
原文地址:https://www.cnblogs.com/yijiushengjing/p/10323091.html