表结构是: classID,className,parentId ,depth,allChildId , ................ public String getSelectTree( String classID) ... { Stack stack = new Stack(); StringBuffer tree = new StringBuffer(" "); List list = this.siteClassDao.queryRootClass();//得到根 if (list != null && list.size() != 0) ...{ for (int i = 0; i < list.size(); i++) ...{ stack.push(((TCmsSiteClass) list.get(i)).getClassID()); } } TCmsSiteClass po = null; String[] children = null; TCmsSiteClass parent = null; int dep=0; String space=" "; StringBuffer perSpace = new StringBuffer(" "); while (!stack.isEmpty()) ...{ parent = null; po = this.siteClassDao.querySiteClass((String) stack.pop()); if (po.getParentId().length() == 32) ...{ parent = this.siteClassDao.querySiteClass(po.getParentId()); } else ...{ dep=0; perSpace.delete(0,perSpace.length()); } if(po.getDepth().intValue()>dep)...{ dep++; perSpace.append(space); } else if(po.getDepth().intValue()<=dep)...{ perSpace.delete(perSpace.length()-(space.length()*(dep-po.getDepth().intValue())),perSpace.length()); if(perSpace.length()>1&&perSpace.charAt(perSpace.length()-1)!=';')...{ perSpace.deleteCharAt(perSpace.length()-1); } dep=po.getDepth().intValue(); } tree.append("<option "); if (po.getClassID().equals(classID)) ...{ tree.append(" selected "); } tree.append("value='"); tree.append(po.getClassID()); tree.append("'>"); // 判断此节点 是不是 所有兄弟节点里面的最后一个 if (parent != null) ...{ int i; String[] brotherIDs = StrUtils.split(parent.getAllChildId(), '#'); for (i = 0; i < brotherIDs.length - 1; i++) ...{ if (po.getClassID().equals(brotherIDs[i])) ...{ break; } } if (i == 0) ...{ // 是所有兄弟节点里面的最后一个 tree.append(perSpace); tree.append("└ "); } else ...{ tree.append(perSpace); tree.append("├ "); // 不是所有兄弟节点里面的最后一个 perSpace.append("│"); } } tree.append(po.getClassName()); tree.append("</option> "); // 把所有孩子的ID加到 堆栈里面去 if (po.getAllChildId() != null) ...{ children = StrUtils.split(po.getAllChildId(), '#'); for (int i = 0; i < children.length - 1; i++) ...{ stack.push(children[i]); } } } return tree.toString(); }