浏览 2386 次
锁定老帖子 主题:面向对象的树型结构设计与实现
精华帖 (0) :: 良好帖 (0) :: 新手帖 (2) :: 隐藏帖 (8)
|
|
---|---|
作者 | 正文 |
发表时间:2009-08-24
Orgnization.java package com.changtu.oa.model; import java.util.Set; /** * 组织机构(树型结构) * @author Mike * */ public class Orgnization { private int id; /** * 机构名称 */ private String name; /** * */ private String sn; /** * 机构描述 */ private String description; /** * 树型结构,一对多的双向关联 */ private Orgnization parent; private Set children; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSn() { return sn; } public void setSn(String sn) { this.sn = sn; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Orgnization getParent() { return parent; } public void setParent(Orgnization parent) { this.parent = parent; } public Set getChildren() { return children; } public void setChildren(Set children) { this.children = children; } } hibernate的映射配置:Orgnization.hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class table="T_Orgnization" name="com.changtu.oa.model.Orgnization"> <id name="id"> <generator class="identity" /> </id> <property name="name"></property> <property name="sn"></property> <property name="description"></property> <!-- 树型结构,一对多双向关联 --> <many-to-one name="parent" column="pid" lazy="false"></many-to-one> <set name="children" inverse="true" cascade="all"> <key column="pid"></key> <one-to-many class="com.changtu.oa.model.Orgnization" /> </set> </class> </hibernate-mapping> 以上是实体以及hibernate配置文件的编写,具体服务层接口的定义与实现和呈现层的实现可以根据的需求去给予实现。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-09-08
貌似自连接。
|
|
返回顶楼 | |