Day 17 - MySQL 使用Annontation設定欄位 (1)
上一章介紹了Model層的相關Annontation
接下來把我們每一個Model都加上設定
Certificate.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "certificate")
public class Certificate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "certificate_id", unique = true, nullable = false)
private Long certificateId;
@NonNull
@Column(name = "name", unique = true, nullable = false, length = 50)
private String name;
@ManyToOne
@JoinColumn(name = "skill_id")
@NonNull
private Skill skill;
@ManyToOne
@JoinColumn(name = "company_id")
@NonNull
private Company company;
}
Company.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "company")
public class Company {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "company_id", unique = true, nullable = false)
private Long companyId;
@NonNull
@Column(name = "name", unique = true, nullable = false, length = 50)
private String name;
}
ExamInfo.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "exam_info")
public class ExamInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "exam_id", unique = true, nullable = false)
private Long examId;
@ManyToOne
@JoinColumn(name = "certificate_id")
@NonNull
private Certificate certificate;
@ManyToOne
@JoinColumn(name = "vendor_id")
@NonNull
private Vendor vendor;
@NonNull
@Column(name = "exam_date")
private Date examDate;
@NonNull
@Column(name = "publish_date")
private Date publishDate;
}
MemberExam.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "member_exam")
public class MemberExam {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_exam_id", unique = true, nullable = false)
private Long memberExamId;
@ManyToOne
@JoinColumn(name = "mid")
@NonNull
private Member member;
@ManyToOne
@JoinColumn(name = "exam_id")
private ExamInfo examInfo;
@Column(name = "join_time")
private Date joinTime;
}
MemberSkill.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "member_skill")
public class MemberSkill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_skill_id", unique = true, nullable = false)
private Long memberSkillId;
@ManyToOne
@JoinColumn(name = "mid")
@NonNull
private Member member;
@ManyToOne
@JoinColumn(name = "skill_id")
@NonNull
private Skill skill;
}
Skill.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "skill")
public class Skill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "skill_id", unique = true, nullable = false)
private Long skillId;
@NonNull
@Column(name = "name", nullable = false, length = 50)
private String name;
@NonNull
@Column(name = "type", nullable = false, length = 50)
private String type;
}
Vendor.java
@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
@Table(name = "vendor")
public class Vendor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "vendor_id", unique = true, nullable = false)
private Long vendorId;
@NonNull
@Column(name = "name", unique = true, nullable = false, length = 50)
private String name;
}
這樣就都新增完成, 可以打開MySQL Workbench 8.0 看看是不是Table都出來了
下一章 Day 19 - React 什麼是React? 要怎麼用?