添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
@GeneratedValue(strategy = GenerationType.IDENTITY) private Long skillId; private String name; private String type; public Long getSkillId() { return skillId; public void setSkillId(Long skillId) { this.skillId = skillId; public String getName() { return name; public void setName(String name) { this.name = name; public String getType() { return type; public void setType(String type) { this.type = type;

新增Company.java

@Entity
public class Company {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long companyId;
    private String name;
    public Long getCompanyId() {
        return companyId;
    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;

新增Certificate.java

@Entity
public class Certificate {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long certificateId;
    private String name;
    @ManyToOne
    @JoinColumn(name = "skillId")
    private Skill skill;
    @ManyToOne
    @JoinColumn(name = "companyId")
    private Company company;
    public Long getCertificateId() {
        return certificateId;
    public void setCertificateId(Long certificateId) {
        this.certificateId = certificateId;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;
    public Skill getSkill() {
        return skill;
    public void setSkill(Skill skill) {
        this.skill = skill;
    public Company getCompany() {
        return company;
    public void setCompany(Company company) {
        this.company = company;

新增Vendor.java

@Entity
public class Vendor {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long vendorId;
    private String name;
    public Long getVendorId() {
        return vendorId;
    public void setVendorId(Long vendorId) {
        this.vendorId = vendorId;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;

新增ExamInfo.java

@Entity
public class Vendor {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long vendorId;
    private String name;
    public Long getVendorId() {
        return vendorId;
    public void setVendorId(Long vendorId) {
        this.vendorId = vendorId;
    public String getName() {
        return name;
    public void setName(String name) {
        this.name = name;

新增MemberExam.java

@Entity
public class MemberExam {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long memberExamId;
    @ManyToOne
    @JoinColumn(name = "mid")
    private Member member;
    @ManyToOne
    @JoinColumn(name = "examId")
    private ExamInfo examInfo;
    private Date joinTime;
    public Long getMemberExamId() {
        return memberExamId;
    public void setMemberExamId(Long memberExamId) {
        this.memberExamId = memberExamId;
    public Member getMember() {
        return member;
    public void setMember(Member member) {
        this.member = member;
    public ExamInfo getExamInfo() {
        return examInfo;
    public void setExamInfo(ExamInfo examInfo) {
        this.examInfo = examInfo;
    public Date getJoinTime() {
    return joinTime;
    public void setJoinTime(Date joinTime) {
        this.joinTime = joinTime;

新增MemberSkill.java

@Entity
public class MemberSkill {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long memberSkillId;
    @ManyToOne
    @JoinColumn(name = "mid")
    private Member member;
    @ManyToOne
    @JoinColumn(name = "skillId")
    private Skill skill;
    public Long getId() {
        return id;
    public void setId(Long id) {
        this.id = id;
    public Member getMember() {
        return member;
    public void setMember(Member member) {
        this.member = member;
    public Skill getSkill() {
        return skill;
    public void setSkill(Skill skill) {
        this.skill = skill;

簡單講一下我們Model用到的Annotation

@Entity - 聲明為實體類, ORM映射對象

@Id - 聲明為主鍵

@GeneratedValue(strategy = GenerationType.IDENTITY) - 自動產生流水號

@OneToMany - 聲明關係為一對多

@ManyToOne - 聲明關係為多對一

@JoinColumn - 多對一或一對多時, 要對應到的欄位

下一章 Spring Data JPA 寫入與讀取資料 (3)