oa组织机构(树状结构)

package com.bjsxt.oa.model;

import java.util.Set;

public class Organization {
	private int id;
	private String name;
	private String sn;
	private String description;
	private Organization 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 Organization getParent() {
		return parent;
	}
	public void setParent(Organization parent) {
		this.parent = parent;
	}
	public Set getChildren() {
		return children;
	}
	public void setChildren(Set children) {
		this.children = children;
	}
}

<?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 name="com.bjsxt.oa.model.Organization" table="t_organization">
		<id name="id">
			<generator class="native"/>
		</id>
		<property name="name"/>
		<property name="sn"/>
		<property name="description"/>
		<many-to-one name="parent" column="[color=red]pid[/color]"></many-to-one>
		<set name="children" lazy="extra" inverse="true">
			<key column="[color=red]pid[/color]"></key>
			<one-to-many class="com.bjsxt.oa.model.Organization"/>
		</set>
	</class>
</hibernate-mapping>
many-to-one one-to-many 双向关联
这里的pid要一样
inverse=true 主控表为多的一方


package com.bjsxt.oa.model;

public class Person {
	private int id;
	private String name;
	private String sex;
	private String address;
	private int age;
	private String duty;
	private String phone;
	private Organization org;
	
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getDuty() {
		return duty;
	}
	public void setDuty(String duty) {
		this.duty = duty;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public Organization getOrg() {
		return org;
	}
	public void setOrg(Organization org) {
		this.org = org;
	}
	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;
	}
}



<?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 name="com.bjsxt.oa.model.Person" table="t_person">
		<id name="id">
			<generator class="native"/>
		</id>
		<property name="name"/>
		<property name="sex"/>
		<property name="age"/>
		<property name="address"/>
		<property name="duty"/>
		<property name="phone"/>
		<many-to-one name="org"></many-to-one>
	</class>
</hibernate-mapping>
人员和组织机构的关系是many-to-one单向外键关联
这里的分页是用pagertaglib
在Criteria接口中有两个方法:setFirstResult方法和setMaxResults方法。
其中setFirstResult设置了记录的开始位置(0表示第1条记录),
setMaxResults设置了返回的记录数。
下面是完整代码:
jar包是ssh整合的jar包
其它文章提供下载了

你可能感兴趣的:(ssh)