A recursive loop is used to load easyui tree structure data

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;
}

There needs to be a fatherId field to record who his parent is

goodsTypeId is the ID of the table I am querying

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327082743&siteId=291194637