通过后台实现

private List<Photo> getChildren(Photo photo) {
        List<Photo> children = new ArrayList<>();
        if (!photoList.isEmpty()) {
            photoList.stream().filter(child -> photo.getId().equals(child.getParentId())).forEach(child -> {
                List<Photo> tmp = getChildren(child);
                child.setChildren(tmp);
                if (tmp.isEmpty()) {
                    child.setLeaf(true);
                }
                Boolean leaf = photo.getLeaf();
                Integer parentId = child.getParentId();
                if(leaf == null){
                    Integer childNodes = photoDao.countChildNodes(parentId);
                    if (photo.getText().indexOf("(")==-1) {
                        photo.setText(photo.getText() + "(" + childNodes + ")");
                    }
                }
                children.add(child);
            });
        }
        return children;
    }

 

效果如下

Java给树加子节点个数统计

 

相关文章:

  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-07-26
  • 2022-02-28
相关资源
相似解决方案