easyui树型菜单后台数据递归转换

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;
		
	}
	
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值