N-level menu recursive query

Source: Internet
Author: User

/** assemble all the menus into a tree * @param classdtolist database query all menu * Menu list * @return list<classdto> */private list<classdto& Gt Assembleclasstree (list<classdto> classdtolist) {list<classdto> classtreelist = Null;if ( Commonutils.listnotnull (classdtolist)) {classtreelist = new arraylist<classdto> (); for (Classdto classDTO1: Classdtolist) {if (Classdto1.islevel1 ()) {This.setchildclass (classDTO1, classdtolist); Classtreelist.add (classDTO1) ;}}} return classtreelist;} /** Assemble the menu tree by recursive method * @param classdto * @param classdtolist * @return */private void Setchildclass (Classdto parentclassdto, L ist<classdto> classdtolist) {list<classdto> childclasslist = Parentclassdto.getchildlist (); if ( Childclasslist = = null) {childclasslist = new arraylist<classdto> ();p arentclassdto.setchildlist (childClassList );} for (Classdto childclassdto:classdtolist) {if (Parentclassdto.getidclass (). Equals (Childclassdto.getidparentclass () ) {Childclasslist.add (childclassdto); This.setchildclass (ChildclasSdto, classdtolist);}}} 




  

  

/** gets the subset of ParentID under a recursive method * @param parentid Parent ID * @param allclasstree menu Tree Collection * @return */private list<classdto> g Etchildclassbyparentid (String parentid, list<classdto> allclasstree) {for (classdto classdto:allclasstree) {// If ParentID is found, all the sub-sections under this palette are returned with the IF (Classdto.getidclass (). Equals (ParentID)) {return classdto.getchildlist (); Otherwise, continue looking for else {list<classdto> childlist = Classdto.getchildlist (); if (Commonutils.listnotnull (childlist)) { Childlist = This.getchildclassbyparentid (ParentID, childlist); if (childlist! = null) {return childlist;} else {continue;}}} return null;}

  

/** *  gives a tree recursively to its next leaf node * @param alltree  tree * @param leafclasslist   leaf node * @throws businessserviceexception * /private void Loopleafclasslistbytree (list<classdto> alltree, list<classdto> leafClassList) {if ( Commonutils.listnotnull (Alltree)) {for (classdto classdto:alltree) {if (Classdto.isleafclass ()) {Leafclasslist.add ( Classdto);} else {list<classdto> childclasslist = Classdto.getchildlist (); if (Commonutils.listnotnull (childClassList)) { This.loopleafclasslistbytree (Childclasslist, leafclasslist);}}}}

  

N-level menu recursive query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.