SSH-BOS project: dynamically load function menu

FunctionAction (new method):

	/**
	 * Load the menu displayed by the current user
	 * @return
	 */
	public String loadMenu(){
		List<Function> list = functionService.loadMenu();
		BOSUtils.writerJson(list, new String[]{"parentFunction","roles","children"});
		
		return NONE;
	}

FunctionService, FunctionServiceImpl (new methods and their implementation):

	/**
	 * Load current user's menu
	 * @return
	 */
	List<Function> loadMenu();
	@Override
	public List<Function> loadMenu() {
		User user = BOSUtils.getLoginUser();
		List<Function> list = null;
		//If the current user is a system administrator account
		if(user.getUsername().equals("admin")){
			//load all menus for sysadmin
			list = functionDao.findByAdminMenu();
		}else{
			//Load the corresponding menu for ordinary users
			list = functionDao.findByUserMenu(user.getId());
		}
		
		return list;
	}

FunctionDao, FunctionDaoImpl (new methods and their implementation):

	/**
	 * Query the menu information of the super administrator
	 * @return
	 */
	List<Function> findByAdminMenu();

	/**
	 * Query the information of the specified user menu
	 * @return
	 */
	List<Function> findByUserMenu(String userId);
	@Override
	public List<Function> findByAdminMenu() {
		String hql = "FROM Function f WHERE f.generatemenu = '1' ORDER BY f.zindex DESC";
		return (List<Function>) this.getHibernateTemplate().find(hql);
	}

	@Override
	public List<Function> findByUserMenu(String userId) {
		String hql = "SELECT DISTINCT f FROM Function f LEFT OUTER JOIN f.roles"
				+ " r LEFT OUTER JOIN r.users u WHERE u.id = ? AND f.generatemenu = '1' "
				+ "ORDER BY f.zindex DESC";
		return (List<Function>) this.getHibernateTemplate().find(hql, userId);
	}

page:

Modify the URL loaded by the basic function menu. as follows:

		// load the basic function menu
		$.ajax({
			url : '${pageContext.request.contextPath}/FunctionAction_loadMenu.action',
			type : 'POST',
			dataType : 'text',
			success : function(data) {
				var zNodes = eval("(" + data + ")");
				$.fn.zTree.init($("#treeMenu"), setting, zNodes);
			},
			error : function(msg) {
				alert('Menu loading exception!');
			}
		});



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325956934&siteId=291194637