java常见处理数据结构的方式

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)
                );

 

3.字符串转list

            List<String> excludePathList = Arrays.stream(excludePath.split(","))
                    .filter(s -> StringUtils.isNotBlank(s))
                    .collect(Collectors.toList());

 

dao

1.时间范围筛选

AND NOW() BETWEEN msg_pack.buy_time AND msg_pack.expire_time

 

posted @ 2023-03-09 19:19  fnasklf  阅读(47)  评论(0编辑  收藏  举报