继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

记一次递归查询树

judyW
关注TA
已关注
手记 47
粉丝 11
获赞 107

1,

  Set<AuthResourcePO> authResourcePOSet = Sets.newHashSet();
        Long dialogInitAuthResourceId = 387L;
        //根据父权限id获取该权限以及该权限下所有权限的集合
        authResourcePOSet = findChildAuthResource(authResourcePOSet, dialogInitAuthResourceId);
        //根权限的id得到该权限ID以及该权限下所有子权限ID的集合
        List<Long> authResourceIdList = authResourcePOSet.stream().map(AuthResourcePO::getAuthResourceId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
2,
private Set<AuthResourcePO> findChildAuthResource(Set<AuthResourcePO> authResourcePOSet, Long dialogInitAuthResourceId) {
    AuthResourcePO authResourcePO = authResourceService.selectByKey(dialogInitAuthResourceId);
    if (authResourcePO != null) {
        authResourcePOSet.add(authResourcePO);
    }
    //查找子节点,递归算法一定要有一个退出条件
    List<AuthResourcePO> authResourcePOS = authResourceService.selectByAuthResourceId(dialogInitAuthResourceId);
    for (AuthResourcePO authResourceItem : authResourcePOS) {
        findChildAuthResource(authResourcePOSet, authResourceItem.getAuthResourceId());
    }
    return authResourcePOSet;
}

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP

热门评论

有没有更好的方案呢

查看全部评论