欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hibernate做无限极菜单树如此简单

程序员文章站 2022-06-08 08:38:27
...

hibernate做无限极菜单树如此简单
            
    
    博客分类: hibernate HibernateFlexDAOXMLFlash hibernate做无限极菜单树如此简单
            
    
    博客分类: hibernate HibernateFlexDAOXMLFlash 

package cn.isvi.entity;

import java.util.HashSet;
import java.util.Set;

public class Menu {
	
	private Integer id;
	private String menuName;
	private String parentId;
	private Menu parentMenu;
	private Set<Menu> children=new HashSet<Menu>();
	
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getMenuName() {
		return menuName;
	}
	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}
	public String getParentId() {
		return parentId;
	}
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	public void addMenu(Menu menu){
		children.add(menu);
		menu.parentMenu=this;
	}

	public Set<Menu> getChildren() {
		return children;
	}
	public void setChildren(Set<Menu> children) {
		this.children = children;
	}
	public Menu getParentMenu() {
		return parentMenu;
	}
	public void setParentMenu(Menu parentMenu) {
		this.parentMenu = parentMenu;
	}
}

 

 

package cn.isvi.test;

import cn.isvi.dao.TemplateDAO;
import cn.isvi.dao.impl.TemplateDAOImpl;
import cn.isvi.entity.Menu;

public class MenuTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TemplateDAO tdao=new TemplateDAOImpl();
		Menu menu=new Menu();
		menu.setMenuName("1级");
		
		Menu s1=new Menu();
		s1.setMenuName("2级");
		menu.addMenu(s1);
		
		Menu s2=new Menu();
		s2.setMenuName("3级");
		s1.addMenu(s2);
		try {
			tdao.saveObj(menu);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
	
	<mx:RemoteObject id="menus" destination="menus"
		 endpoint="http://localhost:8400/GDGWeb/messagebroker/amf"
		 result="resultHandle(event)" fault="faultHandle(event)"> 
		
	</mx:RemoteObject> 
	<mx:Script>
		<![CDATA[
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			import mx.collections.ArrayCollection;
			[Bindable]
			private var hibernateData:ArrayCollection;
			
			private function getData():void{
				menus.getMenus();//注意,不能查询所有的Menu,只查询root第一个Menu就可以了
			}
			private function resultHandle(event:ResultEvent):void{
				this.hibernateData=event.result as ArrayCollection;
				trace("得到数据");
			}
			private function faultHandle(event:FaultEvent):void{
				trace(event.message);
			}
		]]>
	</mx:Script>
	<mx:Tree dataProvider="{hibernateData}" labelField="menuName" width="100%" height="90%">
		
	</mx:Tree>
	<mx:Button label="得到数据" click="getData()">
		
	</mx:Button>
</mx:WindowedApplication>
 
  • hibernate做无限极菜单树如此简单
            
    
    博客分类: hibernate HibernateFlexDAOXMLFlash 
  • 大小: 12.9 KB
  • hibernate做无限极菜单树如此简单
            
    
    博客分类: hibernate HibernateFlexDAOXMLFlash 
  • 大小: 3.1 KB
  • hibernate做无限极菜单树如此简单
            
    
    博客分类: hibernate HibernateFlexDAOXMLFlash 
  • 大小: 4 KB