DAO does not write interface, write implementation class directly
Public List<dept> Tree (string hql, string par) { = gethibernatetemplate (). Getsessionfactory () . Getcurrentsession (); New ArrayList (); if (par.length () = = 0) {= session.createquery (hql). List () ; Else { = Session.createquery (HQL). setString (0, par). List (); } return list; }
Service Implementation Class
Public List<dept> Tree (Dept Dept) { = ""; = ""; if (Dept.getid () =null | | dept.getid (). Trim (). Equals ("")) { = "from Dept d where D.dept is null" c12>; } Else { = "from Dept d where d.dept.id =?" ; = Dept.getid (); } return Deptdao.tree (hql, par); }
Action
//Add the tree inside PublicString Comboxtree ()throwsException {List<Dept> FindAll =Deptservice.tree (dept); List List=NewArrayList (); for(Dept dept:findall) {map map=NewHashMap (); if(dept.getdept () = =NULL) {Map.put ("id", Dept.getid ()); Map.put ("Text", Dept.getname ()); Map.put ("pid", 0); Map.put ("State", "closed"); List.add (map); }Else{map.put ("id", Dept.getid ()); Map.put ("Text", Dept.getname ()); Map.put ("pid", Dept.getdept (). GetId ()); List<Dept> depts =Deptservice.tree (dept); if(Depts.size () >0) {Map.put ("State", "closed"); } list.add (map); }} System.out.println (Jsonarray.fromobject (list). ToString ()); System.out.println (); Servletactioncontext.getresponse (). Getwriter (). Write (Jsonarray.fromobject (list). ToString ()); return NULL; }
Easyui Loading the async tree in the background