Java给树加子节点个数统计
Posted 多读书,少说话
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java给树加子节点个数统计相关的知识,希望对你有一定的参考价值。
通过后台实现
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给树加子节点个数统计的主要内容,如果未能解决你的问题,请参考以下文章
java组件JTree问题,怎么给树的子节点注册鼠标双击监听