在action中使用sql按目录的方式查询出部门记录,其中包括部门名称,部门ID,部门父ID。顶头的记录的部门父ID必须为-1,查询语句如: < 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 >< a href ="javascript: tree.openAll();" > 展开所有 </ a > | < 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; |
|