public class MenuDao extends JsonBaseDao{ /** * * @Title: menuList * @Description: 查询后台需要树形展示的菜单表数据 * 注意:该数据转换成json对象,是不符合easyui的tree组件展现的json格式 * @param paramMap * @param pageBean * @return * @return List> * @throws SQLException * @throws IllegalAccessException * @throws InstantiationException */ public List> menuList(Map paramMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{ String sql=" select * from t_easyui_menu where true "; String menuId = JsonUtils.getparamVal(paramMap, "Menuid"); if(StringUtils.isNotBlank(menuId)) { sql+=" and parentid= "+menuId; }else { sql+=" and parentid=-1 "; } return super.executeQuery(sql, pageBean); } /** * * @Title: mapToTreeNode * @Description: 查出来的数据不能展示,转换成可展示的数据 * @param map * @param treeNode * @return void * @throws SQLException * @throws IllegalAccessException * @throws InstantiationException */ private void mapToTreeNode(Map map, TreeNode treeNode) throws InstantiationException, IllegalAccessException, SQLException { treeNode.setId(map.get("Menuid").toString()); treeNode.setText(map.get("Menuname").toString()); treeNode.setAttributes(map); Map paramMap =new HashMap<>(); //把当前节点的id 当作父id,查出所有的子节点 paramMap.put("Menuid", new String[ ] {treeNode.getId() }); List> menuList = this.menuList(paramMap, null); List TreeNodeList = new ArrayList<>(); mapListToTreeNodeList(menuList, TreeNodeList); treeNode.setChildren(TreeNodeList); } private void mapListToTreeNodeList(List> list, List TreeNodeList) throws InstantiationException, IllegalAccessException, SQLException { TreeNode treeNode=null; for (Map map : list) { treeNode=new TreeNode(); mapToTreeNode(map, treeNode); TreeNodeList.add(treeNode); } } /** * * @Title: menuTreeList * @Description: 这个方法的返回值才是符合easyui的tree组件所需要的json格式 * @param paramMap * @param pageBean * @return * @throws InstantiationException * @throws IllegalAccessException * @throws SQLException * @return List */ public List menuTreeList(Map paramMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{ List> menuList = this.menuList(paramMap, pageBean); List TreeNodeList = new ArrayList<>(); mapListToTreeNodeList(menuList, TreeNodeList); return TreeNodeList; } }