1】把tree定义在一个空<ul>元素
2】使用Javascript加载数据
3】resourceController中的tree方法
@RequestMapping("/tree")@ResponseBodypublic Listtree(HttpSession session) { //获取当前账户的用户信息(包括ID/登录名/用户可以访问的资源地址列表) SessionInfo sessionInfo = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName()); return resourceService.tree(sessionInfo);}
4】resourceService的tree方法
public Listtree(SessionInfo sessionInfo) { List l = null; List lt = new ArrayList (); Map params = new HashMap (); params.put("resourceTypeId", "0");// 菜单类型的资源 if (sessionInfo != null) { params.put("userId", sessionInfo.getId());// 自查自己有权限的资源 l = resourceDao.find("select distinct t from Tresource t join fetch t.tresourcetype type join fetch t.troles role join role.tusers user where type.id = :resourceTypeId and user.id = :userId order by t.seq", params); } else { l = resourceDao.find("select distinct t from Tresource t join fetch t.tresourcetype type where type.id = :resourceTypeId order by t.seq", params); } if (l != null && l.size() > 0) { for (Tresource r : l) { Tree tree = new Tree(); BeanUtils.copyProperties(r, tree); if (r.getTresource() != null) { tree.setPid(r.getTresource().getId()); } tree.setText(r.getName()); tree.setIconCls(r.getIcon()); Map attr = new HashMap (); attr.put("url", r.getUrl()); tree.setAttributes(attr); lt.add(tree); } } log.info("debug级别的日志输出----"+JSON.toJSONString(lt)); return lt; }
5】返回的JSON数据如下:
[ { "attributes": {}, "checked": false, "iconCls": "plugin", "id": "xtgl", "state": "open", "text": "系统管理" }, { "attributes": { "url": "/chartController/userCreateDatetimeChart" }, "checked": false, "iconCls": "chart_curve", "id": "userCreateDatetimeChart", "pid": "chart", "state": "open", "text": "用户图表" }, { "attributes": { "url": "/resourceController/manager" }, "checked": false, "iconCls": "database_gear", "id": "zygl", "pid": "xtgl", "state": "open", "text": "资源管理" }, { "attributes": { "url": "/roleController/manager" }, "checked": false, "iconCls": "tux", "id": "jsgl", "pid": "xtgl", "state": "open", "text": "角色管理" }, { "attributes": { "url": "/userController/manager" }, "checked": false, "iconCls": "status_online", "id": "yhgl", "pid": "xtgl", "state": "open", "text": "用户管理" }, { "attributes": { "url": "/bugController/manager" }, "checked": false, "iconCls": "bug", "id": "buggl", "pid": "xtgl", "state": "open", "text": "BUG管理" }, { "attributes": { "url": "/druidController/druid" }, "checked": false, "iconCls": "server_database", "id": "sjygl", "pid": "xtgl", "state": "open", "text": "数据源管理" }]