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;
}
需要有一个 fatherId 字段来记录他的父节点是谁
goodsTypeId 是我查询的那张表的ID