获取父节点下的子节点 --- 递归

/**
* 显示节点一级目录
*/
@RequestMapping(value = "/getMallCategoryInfo.shtml")
public Result getMallCategoryInfo() {
List list = new ArrayList();
List<MallCategoryInfo> mallCategoryInfo = manager.createQuery("from MallCategoryInfo where nodeLevel = 1 and enable = 'Y' ", MallCategoryInfo.class).getResultList();
for (MallCategoryInfo categoryInfo : mallCategoryInfo) {
Map<String, Object> map = new HashMap<>();
map.put("text", categoryInfo.getNodeName()+"<input type='hidden' id='"+categoryInfo.getNodeId()+"'/>");
getTree(categoryInfo.getNodeId(), map);
list.add(map);
}
return Results.SUCCESS.build(list);
}
/**
* 递归 二级目录以下的节点
* @param nodeId
* @param map
*/
private void getTree(String nodeId, Map<String, Object> map) {
List<MallCategoryInfo> category = manager.createQuery("from MallCategoryInfo where enable = 'Y' and parentNodeId = ?1", MallCategoryInfo.class).setParameter(1, nodeId).getResultList();
List listMap = new ArrayList();
map.put("nodes", listMap);
for (MallCategoryInfo mallCategory :category) {
Map<String, Object> para = new HashMap<>();
para.put("text", mallCategory.getNodeName()+"<input type='hidden' id='"+mallCategory.getNodeId()+"'/>");
listMap.add(para);
getTree(mallCategory.getNodeId(), para);
}
}

posted @ 2017-07-26 10:45  南国的刘新  阅读(638)  评论(0编辑  收藏  举报