Structure design of database organization tree
Java implementation code, splicing XML organization tree
Public String Loadareatree () {StringBuffer areatreestr = new StringBuffer ();
Areatreestr.append ("<>"); Check out all the countries in the first level region list<area> countrylist = Hibernatetemplate.getsessionfactory (). Opensession (). CreateQuery ("
From area p where P.parentareano = ' # ' and p.isvisible = ' true ' ORDER by P.leafno '). List (); if (countrylist!= null && countrylist.size () > 0) {for (area countryarea:countrylist) {Areatreestr.ap
Pend ("<country areaname=\" "+countryarea.getareaname () +" "Urls=\" "+countryarea.geturls () +" ">");
Check out all provinces in the second tier (under the country) list<area> provincearealist = Hibernatetemplate.getsessionfactory (). Opensession ()
. CreateQuery ("from area p where P.parentareano =:countryareano and p.isvisible = ' true ' ORDER by P.leafno")
. SetString ("Countryareano", Countryarea.getareano (). toString ()). List (); if (provincearealist!= null && provincearealist.size () > 0) {for (area Provincearea:provincearealiST) {areatreestr.append ("<province areaname=\" "+provincearea.getareaname () +" \ urls=\ "" +provincearea.geturls ()
+ ">");
Check out all cities in the third-tier region (under the province) list<area> cityarealist = Hibernatetemplate.getsessionfactory (). Opensession ()
. CreateQuery ("from area p where P.parentareano =:p Rovinceareano and p.isvisible = ' true ' ORDER by P.leafno")
. SetString ("Provinceareano", Provincearea.getareano (). toString ()). List (); if (cityarealist!= null && cityarealist.size () > 0) {for (area cityarea:cityarealist) {Areatr Eestr.append ("<city areaname=\" "+cityarea.getareaname () +" \ urls=\ "" +cityarea.geturls () + "></city>"
);
} areatreestr.append ("</province>");
} areatreestr.append ("</country>");
Return Areatreestr.append ("</>"). ToString ();
}else{return ""; }
}
Interface display
Clicking on the menu will link to the specified URL