javaweb里面树形结构(tree)
publicStringqueryTree(){List<Department>nodes=null;intparentId=Integer.parseInt(reque...
public String queryTree(){
List<Department> nodes = null;
int parentId = Integer.parseInt(request.getParameter("parentId"));//获取parentId
Map<String,Object> params = new HashMap<String, Object>();
params.put("parentId", parentId);
params.put("status", 1);
nodes = departmentService.query(params);//查询当前节点下的子节点
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();//用于封装json
for(Department node: nodes){
Map<String,Object> item = new HashMap<String,Object>();
item.put("id", node.getDepartmentId());
item.put("text", node.getDepartmentName());
params.put("parentId", node.getDepartmentId());
int count = departmentService.count(params);
if (count > 0){
item.put("state", "closed");
}
items.add(item);
}
return null;
}
想知道为什么这段代码的for循环条件是这样的,是什么意思。 for(Department node: nodes)。感谢 展开
List<Department> nodes = null;
int parentId = Integer.parseInt(request.getParameter("parentId"));//获取parentId
Map<String,Object> params = new HashMap<String, Object>();
params.put("parentId", parentId);
params.put("status", 1);
nodes = departmentService.query(params);//查询当前节点下的子节点
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();//用于封装json
for(Department node: nodes){
Map<String,Object> item = new HashMap<String,Object>();
item.put("id", node.getDepartmentId());
item.put("text", node.getDepartmentName());
params.put("parentId", node.getDepartmentId());
int count = departmentService.count(params);
if (count > 0){
item.put("state", "closed");
}
items.add(item);
}
return null;
}
想知道为什么这段代码的for循环条件是这样的,是什么意思。 for(Department node: nodes)。感谢 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询