Java:递归获得树任意节点的子子孙孙节点
private List<String> childrenWithIds = new ArrayList<>();
protected List<String> getOrgFatherAndSonIds(List<PartyOrganizationInformation> listAll, String id){
this.childrenWithIds.clear();
List<String> list = recursionGetIds(listAll, id);
list.add(id);
return list;
}
private List<String> recursionGetIds(List<PartyOrganizationInformation> list, String id){
for (PartyOrganizationInformation p:list){
if (p.getForeignKey().equals(id)){
recursionGetIds(list, p.getId());
childrenWithIds.add(p.getId());
}
}
return childrenWithIds;
}