A burst of OA project, there is an organizational structure of the tree, because it is done separately, I do the controller and the page, the other team to do the service and DAO, because the page has not been discussed with what framework to do better, resulting in, the DAO layer taken out of the data are not Easyui What the tree can recognize, in fact, is the tree-shaped structure returned by the back, but they return to the **id, not the ID Easyui tree can recognize; they return name, not the text that Easyui tree can recognize, they return the * * *, Rather than Easyui tree can recognize the children, because others have done, so it is not convenient for others to define the format, so I can only by the turn VO, the service returned to the object to encapsulate, so that it support Easyui, say not much, directly on the code.
This is the VO code, the main thing is Id,text,children, to turn is the three
public class Organizationvo implements serializable{private Integer ID; Private Integer pid; Private Integer Teamid; private String text; Private String State; Private String leader; Private Integer sort; Private list<organizationvo> children; Public Organizationvo () {} public organizationvo (integer id,integer pid, integer teamid,string leader,integer sort,strin G text,string State, list<organizationvo> children) {this.id = ID; This.pid = pid; This.teamid = Teamid; This.text = text; This.sort = sort; This.leader = leader; This.state = State; This.children = children; } public Integer GetId () {return id; } public void SetId (Integer id) {this.id = ID; } public Integer Getteamid () {return teamid; } public void Setteamid (Integer teamid) {this.teamid = Teamid; } public String GetText () {return text; } public void SettexT (String text) {this.text = text; } public String Getleader () {return leader; } public void Setleader (String leader) {This.leader = leader; } public Integer Getsort () {return sort; } public void Setsort (Integer sort) {this.sort = sort; } public String GetState () {return state; public void SetState (String state) {this.state = state; } public list<organizationvo> GetChildren () {return children; } public void Setchildren (list<organizationvo> children) {This.children = children; } public Integer Getpid () {return PID; } public void Setpid (Integer pid) {this.pid = pid; }}
This is the converted tool class (as long as the organization, without members)
Public classTreenoteutil {/*** Get parent Node Menu *@paramtreeslist all Tree Menu Collection *@return */ Public Final StaticList<organizationvo> Getfathernode (list<teamorganizational>treeslist) {List<OrganizationVo> newtrees =NewArraylist<organizationvo>(); for(teamorganizational teamorganizational:treeslist) {if(Teamorganizational.getfatherid () = =NULL) {//if the PID is empty, the node is the parent node//recursively gets the child nodes under the parent nodeOrganizationvo NewTree =NewOrganizationvo (); Newtree.setid (Teamorganizational.getid ()); Newtree.settext (Teamorganizational.getname ()); Newtree.setteamid (Teamorganizational.getteamid ()); List<TeamOrganizational> treeslists =teamorganizational.getsonteamorganizationals (); Newtree.setchildren (Getchildrennode (Teamorganizational.getid (), treeslists)); Newtrees.add (NewTree); } } returnnewtrees; } /*** Recursive acquisition of child nodes under child nodes *@paramthe ID of the PID parent node *@paramtreeslists All menu Tree Collections *@return */ Private Final StaticList<organizationvo> Getchildrennode (Integer pId, list<teamorganizational>treeslists) {List<OrganizationVo> newtrees =NewArraylist<organizationvo>(); for(teamorganizational mt:treeslists) {if(Mt.getfatherid ()! =NULL) { if(Mt.getfatherid () = =pId) {Organizationvo NewTree=NewOrganizationvo (); //recursively gets the child nodes under the child node, which is the children in the set tree controlNewtree.setchildren (Getchildrennode (Mt.getid (), treeslists)); //setting the data for a tree control attributes propertyNewtree.setid (Mt.getid ()); Newtree.settext (Mt.getname ()); Newtree.setpid (Mt.getfatherid ()); Newtree.setteamid (Mt.getteamid ()); Newtree.setsort (Mt.getsort ()); Newtree.setleader (Mt.getleader ()); Newtrees.add (NewTree); } } } returnnewtrees; }}
This is the conversion tool class (with organization, with members)
Public classTREENOTEUTIL2 {/*** Get parent Node Menu *@paramtreeslist all Tree Menu Collection *@return */ Public Final StaticList<organizationvo> Getfathernode (list<teamorganizational>treeslist) {List<OrganizationVo> newtrees =NewArraylist<organizationvo>(); for(teamorganizational teamorganizational:treeslist) {if(Teamorganizational.getfatherid () = =NULL) {//if the PID is empty, the node is the parent node//recursively gets the child nodes under the parent nodeOrganizationvo NewTree =NewOrganizationvo (); Newtree.setid (Teamorganizational.getid ()); Newtree.settext (Teamorganizational.getname ()); Newtree.setteamid (Teamorganizational.getteamid ()); List<TeamOrganizational> treeslists =teamorganizational.getsonteamorganizationals (); List<OaUser> treesuserlists =teamorganizational.getoausers (); Newtree.setchildren (Getchildrennode (Teamorganizational.getid (), treeslists,treesuserlists)); Newtrees.add (NewTree); } } returnnewtrees; } /*** Recursive acquisition of child nodes under child nodes *@paramthe ID of the PID parent node *@paramtreeslists All menu Tree Collections *@return */ Private Final StaticList<organizationvo> Getchildrennode (Integer pId, list<teamorganizational> treeslists,list<oauser >treesuserlists) {List<OrganizationVo> newtrees =NewArraylist<organizationvo>(); for(teamorganizational mt:treeslists) {if(Mt.getfatherid ()! =NULL) { if(Mt.getfatherid () = =pId) {Organizationvo NewTree=NewOrganizationvo (); //recursively gets the child nodes under the child node, which is the children in the set tree controlNewtree.setchildren (Getchildrennode (Mt.getid (), treeslists,treesuserlists)); //setting the data for a tree control attributes propertyNewtree.setid (Mt.getid ()); Newtree.settext (Mt.getname ()); Newtree.setpid (Mt.getfatherid ()); Newtree.setteamid (Mt.getteamid ()); Newtree.setsort (Mt.getsort ()); Newtree.setleader (Mt.getleader ()); if(Mt.getoausers (). Size () >0) {Newtree.setchildren (Getoausers (Mt.getoausers ())); } newtrees.add (NewTree); } } } if(Treesuserlists.size () >0){ for(Oauser oauser:treesuserlists) {organizationvo NewTree=NewOrganizationvo (); Newtree.setid (Oauser.getid ()); Newtree.settext (Oauser.getrealname ()); Newtrees.add (NewTree); } } returnnewtrees; } Public StaticList<organizationvo> Getoausers (list<oauser>oausers) {List<OrganizationVo> newtrees =NewArraylist<organizationvo>(); if(Oausers.size () >0){ for(Oauser oauser:oausers) {organizationvo NewTree=NewOrganizationvo (); Newtree.setid (Oauser.getid ()); Newtree.settext (Oauser.getrealname ()); Newtrees.add (NewTree); } }Else{ } returnnewtrees; }}
The code is so much, mainly using the idea of recursion, because you do not know how many levels of the case, or recursion is more convenient, although the loop faster than the recursive speed, occupy less memory, but the recursive return has its advantages;
At the same time, look at those two tools, the second tool analogy the first tool class to add the operation of the staff, but there is no recursion, because the employees will no longer have employees, why I would like to emphasize this, because I first wrote the first tool class, always thinking how to recursion, write the second time, Staff always repeat add, long time can not find the reason, later only suddenly thought, staff below is no staff, then suddenly dawned ....
The Java implementation of the Jquery Easyui tree structure (entity conversion VO)