I do the project when not sure whether the flow diagram shows the node is also a child node, so the recursive way to conduct a circular judgment.
1, Entity Class model
Package Com.ijs.model;
Import java.util.List;
Import javax.persistence.Entity;
Import javax.persistence.Table;
Import javax.persistence.Transient; /** * Processpoint entity. @author myeclipse Persistence Tools */@Entity @Table (name = "Process_point") public class Processpoint extends ABSTRACTP
Rocesspoint implements Java.io.Serializable {//For storing child nodes private list<processpoint> childrenprocesspoint; Constructors/** Default Constructor * * Public Processpoint () {}/** minimal constructor/public processpoin
T (String ID) {super (ID); /** Full Constructor */public Processpoint (string ID, string ProcessID, String code, string name, Integer Ownerro Le, integer owner, integer status, Integer ppord, Integer pptype, String Ppdesc, String pid, Integer pplogic, string Pplogicwith) {super (ID, ProcessID, code, name, Ownerrole, owner, status, Ppord, Pptype, Ppdesc, PID, Pplogic, Pplo
Gicwith); } @Transient public list<processpoint> getChildrenprocesspoint () {return childrenprocesspoint; } public void Setchildrenprocesspoint (list<processpoint> childrenprocesspoint) {this.childrenprocesspoint = Chi
Ldrenprocesspoint; }
}
2. Business Logic Layer Service
Package com.ijs.service;
Import java.util.List;
Import Com.ijs.model.ProcessPoint;
Public interface Processpointserv {
/**
* Gets all node information for recursive iterations using
* @return/public
list< Processpoint> getprocesspoints ();
/**
* According to the current node information ID query the process node information if there are child node information
* @param pid
*
@return
/Public List<processpoint > findbypid (String pid);
3. The business logic layer realizes Serviceimpl
Package Com.ijs.service.impl;
Import java.util.List;
Import Javax.annotation.Resource;
Import Org.springframework.stereotype.Service;
Import Com.ijs.dao.GenericDao;
Import Com.ijs.model.ProcessPoint;
Import Com.ijs.service.ProcessPointServ;
Import Com.ijs.service.ProjectServ; @Service ("Processpointserv") public class Processpointservimpl implements Processpointserv {@Resource private Genericd
AO Genericdao;
Public list<processpoint> getprocesspoints () {StringBuffer jpql = new StringBuffer ();
Jpql.append ("from Processpoint p where 1=1");
Jpql.append ("and p.status = 1");
Jpql.append ("Order By-p.code desc");
list<processpoint> processpoints = This.genericDao.find (jpql.tostring ());
Return processpoints.size () ==0?null:processpoints; @Override public list<processpoint> findbypid (String pid) {if (pid!=null) {StringBuffer jpql = new STRINGB
Uffer ();
Jpql.append ("from Processpoint p where 1=1"); Jpql.append ("and p.status = 1 and P.")Pid= ' "+pid+" ");
Jpql.append ("ORDER by P.ppord");
list<processpoint> processpoints = This.genericDao.find (jpql.tostring ());
Return processpoints.size () ==0?null:processpoints;
return null;
}
}
4, Controller layer controller
Package Com.ijs.control;
Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Comparator;
Import java.util.List;
Import Javax.annotation.Resource;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.web.bind.annotation.ModelAttribute;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;
Import Org.springframework.web.bind.annotation.ResponseBody;
Import Com.ijs.model.ProcessPoint;
Import Com.ijs.service.ProcessPointServ; @Controller @RequestMapping ("/processpoint") public class Processpointcontrol {@Resource (name= "Processpointserv") pr
Ivate Processpointserv Processpointserv; /** * View Project Flowchart * @param processpoint * @return * * * * @RequestMapping (value= "/showprocesspoint", method
= requestmethod.post) public @ResponseBody processpoint showprocesspoint (@ModelAttribute processpoint processpoint) { try {//Handled Flowchart node collection Object list<Processpoint> processpoints =this.getprocesspoints (this.processPointServ.getProcessPoints ()); if (processpoints!=null) {///will handle the collection object of the Flowchart node collection objects (private list<processpoint> childrenprocesspoint;)
Easy to page through the object to take out the data for iterative display processpoint.setchildrenprocesspoint (processpoints);
} catch (Exception e) {e.printstacktrace ();
return processpoint; /** * Process the query out of all flow chart node information for corresponding processing * @param processpoints * @return/private List<processpoint > getprocesspoints (list<processpoint> processpoints) {//Declare a new collection object to receive, store the new node information, and iterate to determine if there is any child node information under the node.
If there is to add list<processpoint> ps=null;
if (processpoints!=null) {ps=new arraylist<processpoint> (); for (Processpoint p:processpoints) {//Find the first level node to start looking for if (P.getpid (). Equals ("0")) {//Call the recursive method to determine whether there are child nodes,
To be added This.addifhaschildren (p);
The nodes that have been iterated and judged are deposited into the new node set Ps.add (p);
}}//Return the new node set back PS; }
/** * Recursive to determine whether the current node object also has child nodes, have to add * @param p/private void Addifhaschildren (Processpoint p) {//according to the current
The node information ID queries whether there are child node information under the process node information list<processpoint> processpoints=this.processpointserv.findbypid (P.getid ()); To determine whether the collection has data, processpoints.size () >2 here is convenient to sort and display the nodes used, the collection must be two objects to compare then sort if (Processpoints!=null &&
Processpoints.size () >2) {///Sort sets the position of the data displayed in parallel 2.1 2.2 2.3 (see below database data structure) Sortlistbycode (processpoints);
}//collection is not empty, add data to P.setchildrenprocesspoint (processpoints); To determine if the collection has data if (P.getchildrenprocesspoint ()!=null) {for (Processpoint Pc:p.getchildrenprocesspoint ()) {////////////////////
Query the Process node information if there are child node information list<processpoint> pc2=this.processpointserv.findbypid (Pc.getid ());
if (Pc2!=null && pc2.size () >2) {//Sort node Sortlistbycode (PC2);
}//Add Node Object Pc.setchildrenprocesspoint (PC2);
Call yourself This.addifhaschildren (PC); /** * Sort Process Menu Node * According to the Code of the node * @param processes/Private void Sortlistbycode (list<processpoint> processpoints) {collections.sort (processpoints, New Comparator< Processpoint> () {@Override public int compare (Processpoint O1, processpoint O2) {float Code1=float.parseflo
At (O1.getcode ());
Float Code2=float.parsefloat (O2.getcode ());
if (Code1>code2) return 1;
else if (Code1==code2) return 0;
else return-1;
}
});
}
}
5, JavaScript data are also used recursively to deal with the corresponding
Here you can use $.ajax to get the data and then iterate here to show Processpoint.findprocesspoint (null,function (data) {//For stitching strings on the page to display var str= "&L
T;ul> "; str+= "<li><a href= ' javascript:; ' class= ' am-badge-secondary ' > ' +data.childrenprocesspoint[0].name+ '
</a> ";
str+= "<ul>";
The sub nodes of the first level node are directly taken to iterate the Var pp=data.childrenprocesspoint[0].childrenprocesspoint;
for (Var i=0;i<pp.length;i++) {var o=pp[i];
str+= "<li><a href= ' javascript:; ' class= ' am-badge-secondary ' >" +o.name+ "</a>";
Recursive call to determine whether there are child nodes under the node Hanschildren (o);
str+= "</li>";
} str+= "</ul>";
str+= "<div class= ' arrow ' ></div>";
str+= "</li></ul>";
Page Show Flowchart Div $ (EL). Find (". Tree"). html (str); Recursive method to determine whether there are child nodes under this node function Hanschildren (o) {if (o.childrenprocesspoint!=undefined) {if (O.childr
enprocesspoint.length>0) {str+= "<ul>"; Forvar j=0;j<o.childrenprocesspoint.length;j++) {var pc=o.childrenprocesspoint[j];
str+= "<li><a href= ' javascript:; ' class= ' am-badge-secondary ' >" +pc.name+ "</a>";
Recursive call Hanschildren (PC);
} str+= "</li></ul>";
str+= "<div class= ' arrow ' ></div>"; }
}
}
});
6, JSP page
<div class= "Add-form clearfix" >
7. Database Data Picture
8, flow chart Display