# 建立Entity相關 ###### tags: `entity` 1. 將重複的 import 以 * 號縮排 2. 在@Entity 下面一排加入@SuppressWarnings({"PersistenceUnitPresent", "ValidPrimaryTableName"}) 3. @NamedQueries 整段拿掉 4. public class ... implements Serializable 的 Serializable 改為 java.io.Serializable -> 改完後 ctrl + shift + i 5. A→Z排序 6. @size、length 移除 7. 刪除 private static .... = 1L,按 ALT + Insert 插入隨機亂數(選 Add generated serialVersionUID) 8. @table 的 name="這個 entity 的檔案名(須小寫)" 的屬性移到第三個位置,若沒name屬性則新增 9. 將每個欄位都加入name(@Column 內新增) 10. 單一欄位為 unique,須在 @Column 設定unique=ture 11. Identifier 欄位 加入@org.hibernate.annotations.Type(type = "pg-uuid") 12. 建構子id欄位移除(若只有單一個 id 欄位,把 public 改 protected,若有多個欄位則把 id 刪除)、如果有Identifier 在建構子內新增,須將其設定為random,型態設為UUID 13. 將onetomany與collection拿掉 14. 加入java doc (每個 method 加入註解) 15. 將多餘的空白行拿掉 16. @Override equals 的 if statement 縮為一排`return !((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)));` 17. Format排版 18. 最後將@Unique與@Unique之間的逗號放至句尾 19. 欄位的型態為 boolen 的話,可將 getter 的名稱 `getXxx` 改為->`isXxx`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up