/**
* 递归获取json tree
* @param parentId 菜单的父id
* @param rootId 根节点id ,递归入口
* @param allMenus 所有的菜单集合
* @return
*/
public List<Menu> getMenuNodes(String parentId, String rootId, List<Menu> allMenus) {
List<Menu> menus = new ArrayList<>();
for (Menu menu : allMenus) {
if (rootId.equals(menu.getStr(parentId) == null ? "" : menu.getStr(parentId))) {
List<Menu> childrenMenu = getMenuNodes(parentId, menu.getStr("F_ID"), allMenus);
if (childrenMenu.size() > 0) {
menu.put("children", childrenMenu);
}
menus.add(menu);
}
}
return menus;
}
/**
* jfinal带集合数据返回html页面,采用freemarker渲染
*/
public void show() {
List<Menu> MenuNodes = Menu.dao.find("select F_ID,F_NAME,F_PARENTID,F_URL,F_ICON from T_SYS_MENU order by F_ORDER");
List<Menu> nodes = getMenuNodes("F_PARENTID", "", MenuNodes);
setAttr("nodes", nodes);
//renderJson();
this.renderFreeMarker("menu2.html");
}