public List<Map<String, Object>> treeWhile(String goodsTypeId){
List<Map<String, Object>> list = jdbcTemplate.queryForList("select goodsTypeId ,typeName from PS_GoodsType where fatherId = " + goodsTypeId);
List<Map<String, Object>> tree = new ArrayList<Map<String,Object>>();
if(list.size()>0){
for(Map<String, Object> map : list){
Map<String, Object> treeMap = new HashMap<String, Object>();
treeMap.put("id", map.get("goodsTypeId"));
treeMap.put("text", map.get("typeName"));
List<Map<String, Object>> children = treeWhile(map.get("goodsTypeId").toString());
treeMap.put("children", children);
tree.add(treeMap);
}
}
return tree;
}get
須要有一個 fatherId 字段來記錄他的父節點是誰List
goodsTypeId 是我查詢的那張表的IDselect