Copy Code code as follows:
Package Com.cjonline.foundation.authority.pojo;
Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Iterator;
Import java.util.List;
Import Org.apache.log4j.Logger;
Import Com.cjonline.foundation.util.CheckNullEmpty;
/**
* Implementation of recursive help classes, the final results can be described as follows:
* Roots (Root)
*--1 (Subsystem 1)
*-----1.1
*-------1.1.1
*-------1.1.2
* ------- ....
*-----1.2
*--2 (Subsystem 2)
*-----2.1
*-------2.1.1
*-------2.1.2
* ------- ....
*-----2.2
*/
public class Modellist implements Java.io.Serializable {
private static final Logger Logger = Logger.getlogger (Modellist.class);
Private static final long serialversionuid = 6384598893693849820L;
/**
* Model represents the current module
*/
Private Sysmodel model;
/**
* Models represents the sub module below the current module,
*/
Private list<modellist> sublist = new arraylist<modellist> ();
/**
* Menu Level
*/
private int flag = 0;
Public Sysmodel Getmodel () {
return model;
}
public void Setmodel (Sysmodel model) {
This.model = model;
}
Public list<modellist> getsublist () {
return sublist;
}
public void Setsublist (list<modellist> sublist) {
This.sublist = sublist;
}
public void Setflag (int flag) {
This.flag = Flag;
}
public int Getflag () {
return flag;
}
/**
* Recursive method to form a hierarchy menu based on the incoming module collection
*/
@SuppressWarnings ("Unchecked")
Public modellist CreateTree2 (list<sysmodel> ms) {
//
Modellist node = new Modellist ();
Arraylist<sysmodel> fu = new arraylist<sysmodel> ();//to store the parent node that parentid is empty;
Arraylist<sysmodel> childs = new arraylist<sysmodel> ();//to store modules that are not systems
Separating the system and module menus
for (iterator<sysmodel> it = Ms.iterator (); It.hasnext ();) {
Sysmodel mode = (Sysmodel) it.next ();
String parentid = Mode.getparentid ();
if (ParentID = null | | parentid.equals ("")) {
Fu.add (mode);
} else {
Childs.add (mode);
}
}
Because it's multiple subsystems, you first need to find out how many subsystems
for (Sysmodel Model:fu) {
Modellist Node1 = new Modellist ();
Node1.setflag (0);
Node1.setmodel (model);
Node.subList.add (Node1);
AppendChild (Node1, Childs);
}
return node;
}
/**
* Node Nodes childs as the sub nodes of the system
*/
public void AppendChild (modellist node, list<sysmodel> Childs) {
if (node!= null) {
String SystemID = Node.getmodel (). Getsystemid ();
String Smid = Node.getmodel (). Getsysmoduleid ();
int flag = Node.getflag ();
if (childs!= null && childs.size () > 0) {
for (Sysmodel model:childs) {
String systemId2 = Model.getsystemid ();
String parentId2 = Model.getparentid ();
if (Systemid.equals (SYSTEMID2)) {
if (Parentid2.equals (Smid)) {
Modellist child = new Modellist ();
Child.setmodel (model);
Child.setflag (flag + 1);
Node.getsublist (). Add (child);
AppendChild (child, Childs);
}
}
}
}
}
}
}