本站不再更新,歡迎光臨 java開發(fā)技術(shù)網(wǎng)
          隨筆-230  評論-230  文章-8  trackbacks-0

          在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();" > 關(guān)閉所有 </ 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方法
          //提取當(dāng)前用戶的部門下拉
            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(
          "提取當(dāng)前用戶的部門下拉出錯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>
          構(gòu)造樹的存儲過程
            /*構(gòu)造樹*/
              
          Function Buildtree(In_Level In NumberReturn Varchar2 As
                  Result 
          Varchar2(4000);
              
          Begin
                  
          If In_Level = 1 Then
                      
          Return Null;
                  
          End If;
                  
          Return '|' || Incstring('-­', (In_Level - 1* 2);
              
          End;
          posted on 2007-01-26 14:18 有貓相伴的日子 閱讀(7829) 評論(6)  編輯  收藏 所屬分類: j2ee

          評論:
          # re: 使用dTree生成部門目錄樹 2007-04-13 09:26 | tyb
          看了N多,就覺得你寫的最好了,舉例說明問題是我最喜歡的,謝謝啦  回復(fù)  更多評論
            
          # re: 使用dTree生成部門目錄樹 2007-04-15 00:10 | 有貓相伴的日子
          常用的東西,希望對大家有所幫助了,歡迎大家多光臨俺的了小blog,我文筆不好,只寫例子,加以簡單文字說明  回復(fù)  更多評論
            
          # re: 使用dTree生成部門目錄樹 2007-05-19 22:06 | dtree問題請教
          樓主對這個dtree.jsp能看懂嗎
          有幾個問題想請教一下  回復(fù)  更多評論
            
          # re: 使用dTree生成部門目錄樹 2007-08-07 10:30 | 4
          看不懂 能不能提供源代碼下載阿 謝謝  回復(fù)  更多評論
            
          # re: 使用dTree生成部門目錄樹 2008-10-06 10:06 | zlm
          真的很不錯!  回復(fù)  更多評論
            
          # re: 使用dTree生成部門目錄樹 2009-02-23 15:16 | 輕輕輕輕輕輕輕輕
          樓主 數(shù)據(jù)庫用的oracle吧?
          問一下在sql server2000中能用sql語句生成樹么?
            回復(fù)  更多評論
            
          本站不再更新,歡迎光臨 java開發(fā)技術(shù)網(wǎng)
          主站蜘蛛池模板: 平南县| 灵山县| 古田县| 公主岭市| 呈贡县| 藁城市| 伊宁市| 建瓯市| 陇川县| 闽清县| 荆门市| 光泽县| 鄱阳县| 西宁市| 历史| 新巴尔虎右旗| 齐齐哈尔市| 岳普湖县| 荔浦县| 天柱县| 宝兴县| 定西市| 安康市| 武威市| 鹤庆县| 英德市| 古田县| 新巴尔虎右旗| 安图县| 巴林右旗| 龙胜| 册亨县| 郎溪县| 延安市| 海阳市| 卢龙县| 紫金县| 成安县| 威海市| 读书| 青岛市|