本文共 3129 字,大约阅读时间需要 10 分钟。
角色实体
package cn.itcast.oa.domain;import java.util.HashSet;import java.util.Set;/** * 岗位 * * @author tyg * */public class Role { private Long id; private String name; private String description; private Setusers = new HashSet (); private Set privileges = new HashSet (); public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Set getUsers() { return users; } public void setUsers(Set users) { this.users = users; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Set getPrivileges() { return privileges; } public void setPrivileges(Set privileges) { this.privileges = privileges; }}
权限实体
package cn.itcast.oa.domain;import java.util.HashSet;import java.util.Set;/** * 权限 * * @author tyg * */public class Privilege { private Long id; private String url; private String name; // 权限名称 private Setroles = new HashSet (); private Privilege parent; // 上级权限 private Set children = new HashSet (); // 下级权限 public Privilege() { } public Privilege(String name, String url, Privilege parent) { this.name = name; this.url = url; this.parent = parent; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set getRoles() { return roles; } public void setRoles(Set roles) { this.roles = roles; } public Privilege getParent() { return parent; } public void setParent(Privilege parent) { this.parent = parent; } public Set getChildren() { return children; } public void setChildren(Set children) { this.children = children; }}
两者映射
Hibernate实体映射总结
<!-- users属性,本类与User的一对多 -->
格式:?属性,本类与?的??1 属性名?2 关联对类型?3 关系 多对一: <many-to-one name="" class="" column=""></many-to-one> 一对多(Set): <set name=""> <key column=""></key> <one-to-many class=""/> </set> 多对多(Set): <set name="" table=""> <key column=""></key> <many-to-many class="" column=""></many-to-many> </set>本文出自 “” 博客,请务必保留此出处
转载地址:http://lmovx.baihongyu.com/