Java 學習記錄132 — 員工管理系統專案練習-Create JPA Entity

src\main\java 新增四個資料夾

分別是 controller、exception、model、repository

在 model 裡新增 Employee.java

若是用 Intellij 的話,在 @Table(name = "employees") 應該會報錯

解決方法

All your domain models must be annotated with @Entity annotation. It is used to mark the class as a persistent Java class.

@Table annotation is used to provide the details of the table that this entity will be mapped to.

@Id annotation is used to define the primary key.

@GeneratedValue annotation is used to define the primary key generation strategy.

沒有註明的話就是自增長

等同於 @GeneratedValue(strategy=GenerationType.AUTO)

參考1參考2

GenerationType.AUTO vs GenerationType.IDENTITY in hibernate

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store