这个例子通过三层循环构建了三级树结构,结合使用了list和hashmap个自特有的方法属性。
public HashMap getFlowTreeList()
{
List listOpTp = getSqlSession().selectList("com.cons.pmconf.FlowChart.getOpType");
HashMap mapReturn = new HashMap();
//listOpTp
List newlistOpTp=new ArrayList();
for(int i=0;i<listOpTp.size();i++)
{
HashMap hm=(HashMap)listOpTp.get(i);
int code=Integer.parseInt(hm.get("OPTYPECODE").toString());
flowChart.setOpTypeCode(code);
List flow=getSqlSession().selectList("com.cons.pmconf.FlowChart.getFlowChart",flowChart);
List newflow=new ArrayList();
if(flow.size()>0)
{
for(int j=0;j<flow.size();j++)
{
HashMap fl=(HashMap)flow.get(j);
int flnum=Integer.parseInt(fl.get("FLOWNUM").toString());
flowChart.setFlowNum(flnum);
List vision=getSqlSession().selectList("com.cons.pmconf.FlowChart.getFlowRevision",flowChart);
List newvision=new ArrayList();
for(int k=0;k<vision.size();k++)
{
HashMap vn=(HashMap)vision.get(k);//用HASHMAP存储一条记录,hashmap能够继续添加前台所需要的字段(键值对)
String vnnum = vn.get("FLOWREVISION").toString();
String vnname="版本"+vnnum;
vn.put("TREETYPE", "REV");
vn.put("VNNAME", vnname);
newvision.add(vn);
}
if(fl.get("FLOWTYPE")=="1")
fl.put("TREETYPE", "FC");
else if(fl.get("FLOWTYPE")=="40")
fl.put("TREETYPE", "CHILDFLOW");
else
fl.put("TREETYPE", "ASSISTFLOW");
fl.put("children", newvision);
newflow.add(fl);
}
}
hm.put("TREETYPE", "FT");
hm.put("children", newflow);
newlistOpTp.add(hm);
}
mapReturn.put("TREELIST", newlistOpTp);
return mapReturn;
}