How to use Java code to implement such a directory tree?
Create a data table first
Each data record its own ID and the ID of the parent node
Then go to the Java Code section:
Publicstring Directory (string author) {StringBuffer treehtml=NewStringBuffer (); //get all the directory words (all fields included)list<tutorial> words =Bdexpandservice.getallwords (author); for(inti = 0; I < words.size (); i++) {Tutorial Wordmap=Words.get (i); //System.out.println (wordmap); if(Wordmap.getpid () = = 0) {treehtml.append ("<dl>"); //get the root directory ID, based on this ID to find all subdirectories of thisAppendtree (words, Wordmap, treehtml); Treehtml.append ("</dl>"); }} words.clear (); returntreehtml.tostring (); } /*** * Construct directory tree < feature description > * *@paramTutorials *@paramTutorial *@paramtreehtml *@see[Class, Class # method, Class # member]*/ Private voidAppendtree (list<tutorial>words, Tutorial wordmap, StringBuffer treehtml) { intTid =Wordmap.gettid (); //get the root directory ID, based on this ID to find all subdirectories of thismap<string, object> map =childtreehtml (words, TID); String nodehtml= Map.get ("treehtml"). toString (); BooleanHaschild = boolean.valueof (Map.get ("Haschild"). toString ()); if(haschild) {treehtml.append ("<dt class= ' node-close ' onclick= ' ShowTree ("). Append (Tid). Append (") '"); Treehtml.append ("Id= ' Tree_dt"). Append (Tid). Append ("' >"); Treehtml.append (Wordmap.getkeyword ()). Append ("</dt>"); Treehtml.append (nodehtml); } Else{treehtml.append ("<dt>"); Treehtml.append (Wordmap.getkeyword ()). Append ("</dt>"); } } /*** * Get subdirectories, construct directory tree < feature description > * *@paramTutorials *@paramtid *@return * @see[Class, Class # method, Class # member]*/ PrivateMap<string, object> childtreehtml (list<tutorial> words,inttid) {Map<string, object> map =NewHashmap<string, object>(); StringBuffer treehtml=NewStringBuffer (); BooleanHaschild =false; for(inti = 0; I < words.size (); i++) {Tutorial Wordmap=Words.get (i); intPID =Wordmap.getpid (); if(PID = =tid) {Haschild=true; Treehtml.append ("<dd name= ' Tree_dd"). Append (PID). Append ("'"); Treehtml.append ("Style= ' Display:none; ' > "). Append (" <dl> ").); Appendtree (words, Wordmap, treehtml); Treehtml.append ("</dl></dd>"); }} map.put ("Treehtml", treehtml); Map.put ("Haschild", Haschild); returnmap; }
The string returned by the directory () method is the entire directory tree, which is then uploaded to the foreground page display, plus the CSS style.
Constructing a directory tree with Java code implementation