13.2.3 创建持久化实体类

13.2.3 创建持久化实体类

  • 持久化对象之间的关联关系以成员变量的方式表现出来,当然这些成员变量同样需要settergetter方法的支持。持久化类之间的关联关系通常对应数据库里的主、外键约束
  • 除此之外,持久化对象还有自己的普通类型的成员变量,这些成员变量通常对应数据库的字段

下面是6个持久化类的源代码。

User.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.fkit.hrm.domain;
import java.io.Serializable;
import java.util.Date;
public class User
implements Serializable
{
private static final long serialVersionUID = 1L;
private Integer id; // id
private String username; // 用户名
private String loginname; // 登录名
private String password; // 密码
private Integer userstatus; // 状态
private Date createDate; // 建档日期
// 无参数构造器
public User()
{
super();
}
// setter和getter方法
// 此处省略getter和setter方法,请自己补上
@Override
public String toString()
{
return "User [id=" + id + ", username=" + username + ", loginname=" + loginname
+ ", password=" + password + ", userstatus=" + userstatus + ", createDate="
+ createDate + "]";
}
}

Dept.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package org.fkit.hrm.domain;
import java.io.Serializable;
public class Dept
implements Serializable
{
private static final long serialVersionUID = 1L;
private Integer id; // id
private String name; // 部门名称
private String remark; // 详细描述
// 无参数构造器
public Dept()
{
super();
}
// 此处省略getter和setter方法,请自己补上
@Override
public String toString()
{
return "Dept [id=" + id + ", name=" + name + ", remark=" + remark + "]";
}
}

Job.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package org.fkit.hrm.domain;
import java.io.Serializable;
public class Job
implements Serializable
{
private static final long serialVersionUID = 1L;
private Integer id; // id
private String name; // 职位名称
private String remark; // 详细描述
// 无参数构造器
public Job()
{
super();
}
// 此处省略getter和setter方法,请自己补上
@Override
public String toString()
{
return "Job [id=" + id + ", name=" + name + ", remark=" + remark + "]";
}
}

Employee.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.fkit.hrm.domain;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
public class Employee
implements Serializable
{
private static final long serialVersionUID = 1L;
private Integer id; // id
private Dept dept; // 部门
private Job job; // 职位
private String name; // 名称
private String cardId; // 身份证
private String address; // 地址
private String postCode; // 邮政编码
private String tel; // 电话
private String phone; // 手机
private String qqNum; // qq
private String email; // 邮箱
private Integer sex; // 性别
private String party; // 政治面貌
/**
* 使用@ModelAttribute接收参数时 form表单中有日期,Spring不知道该如何转换,
* 要在实体类的日期属性上加@DateTimeFormat(pattern="yyyy-MM-dd")注解
*/
@DateTimeFormat(pattern = "yyyy-MM-dd")
private java.util.Date birthday; // 生日
private String race; // 名族
private String education; // 学历
private String speciality; // 专业
private String hobby; // 爱好
private String remark; // 备注
private java.util.Date createDate; // 建档日期
// 无参数构造器
public Employee()
{
super();
}
// 此处省略getter和setter方法,请自己补上
@Override
public String toString()
{
return "Employee [id=" + id + ", dept=" + dept + ", job=" + job + ", name=" + name
+ ", cardId=" + cardId + ", address=" + address + ", postCode=" + postCode
+ ", tel=" + tel + ", phone=" + phone + ", qqNum=" + qqNum + ", email=" + email
+ ", sex=" + sex + ", party=" + party + ", birthday=" + birthday + ", race=" + race
+ ", education=" + education + ", speciality=" + speciality + ", hobby=" + hobby
+ ", remark=" + remark + ", createDate=" + createDate + "]";
}
}

Notice.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.fkit.hrm.domain;
import java.io.Serializable;
public class Notice
implements Serializable
{
private static final long serialVersionUID = 1L;
private Integer id; // 编号
private String title; // 标题
private String content; // 内容
private java.util.Date createDate; // 发布日期
private User user; // 发布人
// 无参数构造器
public Notice()
{
super();
// TODO Auto-generated constructor stub
}
// 此处省略getter和setter方法,请自己补上
@Override
public String toString()
{
return "Notice [id=" + id + ", title=" + title + ", content=" + content + ", createDate="
+ createDate + ", user=" + user + "]";
}
}

Document.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package org.fkit.hrm.domain;
import org.springframework.web.multipart.MultipartFile;
import java.io.Serializable;
public class Document
implements Serializable
{
private static final long serialVersionUID = 1L;
private int id; // 编号
private String title; // 标题
private String fileName; // 文件名
private MultipartFile file; // 文件
private String remark; // 描述
private java.util.Date createDate; // 上传时间
private User user; // 上传人
// 无参数构造器
public Document()
{
super();
// TODO Auto-generated constructor stub
}
// 此处省略getter和setter方法,请自己补上
@Override
public String toString()
{
return "Document [id=" + id + ", title=" + title + ", fileName=" + fileName + ", file="
+ file + ", remark=" + remark + ", createDate=" + createDate + ", user=" + user
+ "]";
}
}