使用dTree生成部门目录树

在action中使用sql按目录的方式查询出部门记录,其中包括部门名称,部门ID,部门父ID。顶头的记录的部门父ID必须为-1,查询语句如:
select dept_id,dept_name,parent_id from info_dept connect by prior dept_id = parent_id start with dept_id=?

把获得的list记录set到request中,在页面中显示出来。
页面代码如下:

< link  href ="<%=request.getContextPath()%>/gdnumweb/css/dtree.css"  rel ="stylesheet"  type ="text/css" >
< body >
< script  type ="text/javascript"  src ="<%=request.getContextPath()%>/gdnumweb/js/dtree.js" ></ script >

< div  class ="dtree" >
< p >< href ="javascript: tree.openAll();" > 展开所有 </ a >  |  < href ="javascript: tree.closeAll();" > 关闭所有 </ a ></ p >
< script  language ="javascript"  type ="text/javascript" >
tree 
=   new  dTree('tree');
< logic:iterate id = " dept "  name = " list " >
  tree.add(
" <bean:write name= " dept "  property= " dept_id " /> " , " <bean:write name= " dept "  property= " parent_id " /> " , " <bean:write name= " dept "  property= " dept_name " /> " ,' <%= path %>/ gdnumUserDept. do ? method = getDeptUserInfo & deptNo =< bean:write name = " dept "  property = " dept_id " /> ','','mainframe');
</ logic:iterate >
document.write(tree);
</ script >


在组合框中输出树形目录
获取列表的java方法

// 提取当前用户的部门下拉
   public  List getSourceDept(String deptNo) {
    List list 
=   null ;
    Connection con 
=  CommonUtils.currentSession().connection();
    ResultSet rs 
=   null ;
    ResultSetMetaData rsmd 
=   null ;
    java.sql.PreparedStatement ps 
=   null ;
    String sql 
=   " select deptno,(tools.buildTree(level)||deptname) deptname from sys_dept  "
        
+   " connect by parent_deptno=prior deptno  "
        
+   " start with deptno=? " ;
    HashMap map 
=   null ;
    
try  {
      ps 
=  con.prepareStatement(sql);
      ps.setString(
1 , deptNo);
      rs 
=  ps.executeQuery();
      
// System.out.println("rs.size:" + rs.getFetchSize());
      rsmd  =  rs.getMetaData();
      list 
=   new  ArrayList();
      
while  (rs.next()) {
        map 
=   new  HashMap();
        
for  ( int  i  =   1 ; i  <=  rsmd.getColumnCount(); i ++ ) {
          map.put(rsmd.getColumnName(i).toLowerCase(), rs.getString(i));
        }
        list.add(map);
      }
      rs.close();
    }
    
catch  (Exception ex) {
      log.error(
" 提取当前用户的部门下拉出错com.unicom.gzmas.reports.bo.getSourceDept: "   +  ex);
    }
    
finally  {
      CommonUtils.closeSession();
    }
    
return  list;
  }


页面输出的代码

     < select  id ="mbackdept" >   <!--  部门  -->
          
< option  value ="all" > -----全部---- </ option >
          
< logic:iterate  id ="l"  name ="target" >
          
< option  value ="<bean:write name=" l" property ="deptno" /> "> < bean:write  name ="l"  property ="deptname" /></ option >
          
</ logic:iterate >
    
</ select >

构造树的存储过程

   /* 构造树 */
    
Function  Buildtree(In_Level  In   Number Return   Varchar2   As
        Result 
Varchar2 ( 4000 );
    
Begin
        
If  In_Level  =   1   Then
            
Return   Null ;
        
End   If ;
        
Return   ' | '   ||  Incstring( '- ­ ' , (In_Level  -   1 *   2 );
    
End ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值