EasyDBO 測試版引入註解配置 ORM 映射,核心為 @Table 與 @TableField 兩個運行期保留註解。
@Retention(RetentionPolicy.RUNTIME)
public @interface Table {
String tableName(); // 資料表名稱
String keyField() default "cid"; // 主鍵欄位,預設 "cid"
String keyGenerator() default "com.easyjf.dbo.RandomIdGenerator"; // 主鍵生成器
}
@Retention(RetentionPolicy.RUNTIME)
public @interface TableField {
String name(); // 資料庫欄位名
boolean lazy() default false; // 延遲載入
boolean unique() default false; // 唯一性約束
}
@Table(tableName = "message")
public class Message implements Serializable {
@TableField(name = "cid") private String cid;
@TableField(name = "title") private String title1;
@TableField(name = "content") private String content1;
@TableField(name = "inputUser") private String inputUser;
@TableField(name = "inputTime") private Date inputTime;
@TableField(name = "publish") private Boolean publish1;
@TableField(name = "status") private Integer status1;
// getter/setter...
}
預設主鍵為 cid,生成器為 RandomIdGenerator。
@Table(
tableName = "message",
keyField = "id",
keyGenerator = "com.easyjf.dbo.NullIdGenerator"
)
public class Message implements Serializable {
@TableField(name = "id") private String id;
// 其他欄位...
}
除基本欄位,尚支援關聯關係註解:
@OneToOne:一對一關聯@ManyToOne:多對一關聯@ManyToMany:多對多關聯詳細用法請參考官方開發指南:EasyDBO Development Guide
註解配置功能於正式版仍將持續調整擴充,建議持續關注最新版本釋出資訊與遷移指南。