private List<CatalogVo> toTree(CatalogVo parent, List<CatalogVo> tempList)
throws Exception {
List<CatalogVo> children = findChildren(parent);
// if (children == null || children.size() == 0) {
// return null;
// }
//
// parent.setChildren(children);
for (CatalogVo chidl : children) {
List<CatalogVo> sonList = new ArrayList<CatalogVo>();
chidl.setChildren(sonList);
// children.addAll(toTree(chidl));
tempList.add(chidl);
toTree(chidl, sonList);
}
//
return tempList;
}
//------------------------
private List<CatalogVo> findChildren(CatalogVo parent) throws Exception {
List<CatalogVo> childrenList = new ArrayList<CatalogVo>();
SqlHelper s = new SqlHelper();
try {
// 顶级的data;
String sql = "select * from t_catalog_data where STATUS=? and PARENT_ID=?";
String[] paras = new String[] { "1", String.valueOf(parent.getId()) };
System.out.println(sql + ":" + parent.getId());
ResultSet rs = s.query(sql, paras);
while (rs.next()) {
CatalogVo nextVo = new CatalogVo();
String catName = rs.getString("CAT_NAME");
Integer id = rs.getInt("ID");
nextVo.setCataName(catName);
nextVo.setId(id);
childrenList.add(nextVo);
}
s.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (s != null) {
s.close();
}
}
return childrenList;
}