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; }
效果如下
作者:Rest探路者
出处:http://www.cnblogs.com/Java-Starter/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意请保留此段声明,请在文章页面明显位置给出原文连接
Github:https://github.com/cjy513203427