In this example, a three-level tree structure is built through a three-tier loop, and a list and hashmap are used in combination to create a unique method attribute.
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); // use hashmap to store a record. hashmap can continue to add fields (key-value pairs) required by the foreground)
String vnnum = Vn. Get ("flowrevision"). tostring ();
String vnname = "version" + 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", "workflow flow ");
Fl. Put ("children", newvision );
Newflow. Add (FL );
}
}
Hm. Put ("treetype", "ft ");
Hm. Put ("children", newflow );
Newlistoptp. Add (HM );
}
Mapreturn. Put ("treelist", newlistoptp );
Return mapreturn;
}