1.导入 dtree文件 dtree.css img文件夹 dtree.js
2. 建立对应 的数据库 1 父ID name id
3 建立连接类 mysql 例子
package com.dtree.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;
public class ConnectionManager {
private static final String driver ="org.gjt.mm.mysql.Driver";
private static final String url = "jdbc:mysql://localhost:3306/yuqing?useUnicode=true&characterEncoding=utf8";
private static final String username="root";
private static final String userpwd="zfn";
public static Connection getConnection(){
Connection conn=null;
try{
Class.forName(driver);
conn=DriverManager.getConnection(url,username,userpwd);
}catch(Exception ex){
ex.printStackTrace();
}
return conn;
}
public static void closeConnection(Connection conn){
try{
if(conn!=null && (!conn.isClosed())){
conn.close();
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
public static void closeResultSet(ResultSet res){
try{
if(res!=null){
res.close();
res=null;
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
public static void closeStatement(PreparedStatement stmt){
try{
if(stmt!=null){
stmt.close();
}
}catch(SQLException ex){
ex.printStackTrace();
}
}
}
4. 实现类
package com.dtree.test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class OrganizationService {
private Connection conn;
private PreparedStatement titleQuery;
private ResultSet results;
public List getOrganization(){
List list = new ArrayList();
try {
conn=ConnectionManager.getConnection();
String sql="select * from treetest";
titleQuery=conn.prepareStatement(sql);
results=titleQuery.executeQuery();
while(results.next()){
Organization org1 = new Organization();
org1.setId(results.getInt("id"));
org1.setParentId(results.getInt("parentId"));
org1.setName(results.getString("name"));
list.add(org1);
}
} catch (SQLException e) {
// TODO Auto-