String sql="select * from STS_MALFUNC_SOLUTION s start with s.step_id=? connect by prior s.step_id = s.step_dept_id order by s.step_type Asc";
这是查询当前节点( s.step_id=? )的所有子孙节点(包含当前节点),并按照升序排序。
//菜单树的数据结构 public class GoJsData { private Integer id; private String text; private Integer size; private String color; private String weight; private List<GoJsData> causes = new ArrayList<GoJsData>(); // 子节点集合 public GoJsData(Integer id, String text, Integer size, String color, String weight, List<GoJsData> causes) { super(); this.id = id; this.text = text; this.size = size; this.color = color; this.weight = weight; this.causes = causes; } public GoJsData() { super(); }
}
具体的操作,如下:
@Test public void content() throws IOException { // 1 . 查询数据 STEP_ID:当前节点ID ;STEP_DEPT_ID:父节点ID String sql="select * from STS_MALFUNC_SOLUTION s start with s.step_id=? connect by prior s.step_id = s.step_dept_id order by s.step_type Asc"; List<Map<String,Object>> list= baseDao.queryForList(sql, new Object[] {"11000"}); // 2 . 剥离 当前节点,创建根数据 GoJsData g=null ; for (Map<String, Object> map : list) { String pstepId = String.valueOf(map.get("STEP_DEPT_ID")); if(Integer.valueOf(pstepId)==1) { g = new GoJsData( Integer.valueOf( String.valueOf(map.get("STEP_ID")) ), String.valueOf(map.get("STEP_CONTENT")), 18, "red", "Bold", new ArrayList<GoJsData>()); list.remove(map); break; } } //3 . 递归形成最终树数据 dd(list,g); System.out.println(JSONObject.toJSONString(g)); } // 递归操作 public GoJsData dd(List<Map<String,Object>> list,GoJsData g) { for (Map<String, Object> map : list) { int pstepId = Integer.valueOf(String.valueOf(map.get("STEP_DEPT_ID"))); System.out.println(pstepId); if(g.getId() == pstepId) { GoJsData gj = new GoJsData( Integer.valueOf( String.valueOf(map.get("STEP_ID")) ), String.valueOf(map.get("STEP_CONTENT")), 14, "red", "Bold", new ArrayList<GoJsData>()); g.getCauses().add(gj); dd(list,gj); } } return g; }