easyui 트리 메뉴 백엔드 데이터 변환

2719 단어 sasyui
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;
		
	}
	
}

좋은 웹페이지 즐겨찾기