iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 10
0
Modern Web

Spring Boot and React - 前後端 30 天分手日記系列 第 10

Day 10 - Lombok 簡化與加速開發流程 (2)

  • 分享至 

  • xImage
  •  

Day 9 - Lombok 簡化與加速開發流程 (1)

上一章介紹了Lombok的用法與功能

接下來把其他的Model都更改, 減少我們的程式碼

Certificate.java

@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
public class Certificate {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long certificateId;
    @NonNull
    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
public class Company {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long companyId;
    @NonNull
    private String name;
    
}

ExamInfo.java

@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
public class ExamInfo {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long examId;
    @ManyToOne
    @JoinColumn(name = "certificate_id")
    @NonNull
    private Certificate certificate;
    @ManyToOne
    @JoinColumn(name = "vendor_id")
    @NonNull
    private Vendor vendor;
    @NonNull
    private Date examDate;
    @NonNull
    private Date publishDate;
    
}

MemberExam.java

@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
public class MemberExam {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long memberExamId;
    @ManyToOne
    @JoinColumn(name = "mid")
    @NonNull
    private Member member;
    @ManyToOne
    @JoinColumn(name = "exam_id")
    private ExamInfo examInfo;
    private Date joinTime;
    
}

MemberSkill.java

@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
public class MemberSkill {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    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
public class Skill {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long skillId;
    @NonNull
    private String name;
    @NonNull
    private String type;

}

Vendor.java

@Data
@NoArgsConstructor
@RequiredArgsConstructor
@Entity
public class Vendor {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long vendorId;
    @NonNull
    private String name;

}

如此一來我們的程式碼瞬間少很多行, 讓閱讀變得更容易, 也減少了許多繁複的步驟

Lombok還有許多方便的功能, 例如val, var, @Cleanup, @Value, @Builder, @Log, @EqualsAndHashCode....等等

英文好的朋友可以直接到官網看, 在這裡附上官方網站

https://projectlombok.org

下一章我們正式進入Controller

Day 11 - Controller And RESTful (1)


上一篇
Day 9 - Lombok 簡化與加速開發流程 (1)
下一篇
Day 11 - Controller And RESTful (1)
系列文
Spring Boot and React - 前後端 30 天分手日記30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言