1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
@Data @JsonInclude(JsonInclude.Include.NON_NULL) public class TreeIViewData implements Serializable {
private String id; private String pid; List<TreeIViewData> children; private String title; private boolean expand; private Object obj; <!--.... 省略代码--> }
private List<TreeIViewData> getTreeParentDatas(List<Map<String, Object>> arrayList,String paramPid) { List<TreeIViewData> iViewDataList=new LinkedList<>(); for(Map<String, Object> maps:arrayList){ String id=maps.get("id")+""; String pid=maps.get("pid")+""; String title=maps.get("name")+""; if(StringUtils.equals(pid,paramPid)){ iViewDataList.add(new TreeIViewData(id,pid,title,false)); } } return iViewDataList; }
private void findChildrens(List<Map<String, Object>> arrayList,List<TreeIViewData> treeIViewDataList) { for(TreeIViewData treeIViewData:treeIViewDataList){ List<TreeIViewData> chridrenList=this.getAttentionAtlasTree(arrayList,treeIViewData.getId()); if(chridrenList!=null&&chridrenList.size()>0) findChildrens(arrayList,chridrenList); treeIViewData.setChildren(chridrenList); } }
public static void main(String[] args) { <!--省略代码--> List<Map<String, Object>> arrayList= atlasService.queryForList(sql); List<TreeIViewData> treeIViewDataList=getAttentionAtlasTree(arrayList,"0"); findChildrens(arrayList,treeIViewDataList); System.out.print(JSONObject.toJSONString(treeIViewDataList)); }
|