DozerBeanMapper 工具权限管理递归

Posted yijiushengjing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DozerBeanMapper 工具权限管理递归相关的知识,希望对你有一定的参考价值。

  @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","");
  }

  

以上是关于DozerBeanMapper 工具权限管理递归的主要内容,如果未能解决你的问题,请参考以下文章

JavaBean递归拷贝工具类Dozer

一个DozerBeanMapper配置引发的问题

Django第10章: 权限管理(递归菜单树)

权限管理系统,Lamda递归查询所有菜单

谷粒学院权限管理模块

谷粒学院权限管理模块