Java实现类loadTree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public String loadTree(String nodeID) {
UserModel um = (UserModel) TreadLocalConstant.getSession().getAttribute(ICnsView.LOGIN_USERMODEL);

String deptId = um.getDeptId();

String sql = "SELECT CODE, NAME FROM US_APP.PROVINCE_DISTRICT T, US_APP.DEPTMENT_UNIT_REFER R WHERE T.CODE = R.AREA AND R.STATE_DEPT_CODE = '"
+ deptId + "'";
List<Object[]> list = genericDao.getDataWithNativeSql(sql);

StringBuffer bf = new StringBuffer();

for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[]) list.get(i);
bf.append("{id:'"+obj[0]+"',");
bf.append("text:'"+obj[1]+"'},");
}

String s = bf.toString();

if (s.length() > 0) {
s = s.substring(0, s.length() - 1);
}

return "[" + s + "]";
}

public String loadTreeNode(String nodeID) {
String sql = "SELECT CODE, NAME FROM US_APP.PROVINCE_DISTRICT T WHERE PARENT_CODE = '"
+ nodeID + "'";
List<Object[]> list = genericDao.getDataWithNativeSql(sql);

StringBuffer bf = new StringBuffer();

for (int i = 0; i < list.size(); i++) {
Object[] obj = (Object[]) list.get(i);
bf.append("{id:'"+obj[0]+"',");
bf.append("text:'"+obj[1]+"'},");
}

String s = bf.toString();

if (s.length() > 0) {
s = s.substring(0, s.length() - 1);
}

return "[" + s + "]";
}
坚持原创技术分享,您的支持将鼓励我继续创作!