public class MenuDao extends JsonBaseDao{
/**
*
* @Title: menuList
* @Description: 查询后台需要树形展示的菜单表数据
* 注意:该数据转换成json对象,是不符合easyui的tree组件展现的json格式
* @param paramMap
* @param pageBean
* @return
* @return List<Map<String,Object>>
* @throws SQLException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public List<Map<String, Object>> menuList(Map<String, String[ ]> 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<String, Object> map, TreeNode treeNode) throws InstantiationException, IllegalAccessException, SQLException {
treeNode.setId(map.get("Menuid").toString());
treeNode.setText(map.get("Menuname").toString());
treeNode.setAttributes(map);
Map<String, String[ ]> paramMap =new HashMap<>();
//把当前节点的id 当作父id,查出所有的子节点
paramMap.put("Menuid", new String[ ] {treeNode.getId() });
List<Map<String, Object>> menuList = this.menuList(paramMap, null);
List<TreeNode> TreeNodeList = new ArrayList<>();
mapListToTreeNodeList(menuList, TreeNodeList);
treeNode.setChildren(TreeNodeList);
}
private void mapListToTreeNodeList(List<Map<String, Object>> list, List<TreeNode> TreeNodeList) throws InstantiationException, IllegalAccessException, SQLException {
TreeNode treeNode=null;
for (Map<String, Object> 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<TreeNode>
*/
public List<TreeNode> menuTreeList(Map<String, String[ ]> paramMap,PageBean pageBean) throws InstantiationException, IllegalAccessException, SQLException{
List<Map<String, Object>> menuList = this.menuList(paramMap, pageBean);
List<TreeNode> TreeNodeList = new ArrayList<>();
mapListToTreeNodeList(menuList, TreeNodeList);
return TreeNodeList;
}
}
easyui树型菜单后台数据递归转换
最新推荐文章于 2020-06-22 22:16:25 发布