1.根据父id,将列表整理为树状结构
if (CollUtil.isNotEmpty(sysMenuList)) { //使用java8转为树状图结构 Map<Long, List<SysMenu>> longListMap = sysMenuList.stream().collect(Collectors.groupingBy(SysMenu::getParentId)); sysMenuList.forEach(schMenu -> schMenu.setChildren(longListMap.get(schMenu.getId()))); sysMenuList = sysMenuList.stream().filter(schMenu -> schMenu.getParentId() == 0).collect(Collectors.toList()); }
2.数据根据id去重
sysMenus = sysMenus.stream() .collect(Collectors .collectingAndThen(Collectors .toCollection(() -> new TreeSet<>(Comparator.comparing(SysMenu::getId))), ArrayList::new) );
标签:schMenu,java,sysMenuList,Collectors,常见,collect,stream,数据结构,id From: https://www.cnblogs.com/p201821460026/p/17201126.html