(1)@Entity實(shí)體類注解
- @Entity:表示該類會(huì)對(duì)應(yīng)創(chuàng)建一個(gè)數(shù)據(jù)表,表名默認(rèn)類名大寫
- nameInDb:自定義數(shù)據(jù)庫的名字
@Entity(
nameInDb = "my_student",
generateConstructors = false,
generateGettersSetters = true,
active = true
)
public class Student {
}
- generateConstructors:生成帶參還是不帶參的構(gòu)造方法
- generateGettersSetters:是否生成set/get方法
- active:true表示數(shù)據(jù)表只能插入冠句,不能更新轻掩、刪除等操作
<a name="r0LOJ"></a>
(2)@Id主鍵注解
- 被@Id修飾的成員變量為主鍵,主鍵的基本數(shù)據(jù)類型必須是Long或者long
@Entity
public class Student {
@Id(autoincrement = true)
private long mId;
private String mName;
private int mGender;
}
<a name="Uz24d"></a>
(3)@NotNul
- 當(dāng)前數(shù)據(jù)列不能為空
@Entity
public class Student {
private long mId;
private String mName;
@NotNull
private int mGender;
public Student() {
}
}
<a name="SJkAD"></a>
(4)@Transient
- 添加次標(biāo)記之后不會(huì)生成數(shù)據(jù)庫表的列
<br />
<a name="pumCj"></a>
(5)@Generated @Keep
- @Generated: GreenDao運(yùn)行所產(chǎn)生的構(gòu)造函數(shù)或者方法懦底,被此標(biāo)注的代碼可以變更或者下次運(yùn)行時(shí)清除唇牧。
- @Keep: 注解的代碼段在GreenDao下次運(yùn)行時(shí)保持不變
<a name="qSTr3"></a>
(6)@Unique
- 唯一限制