收藏816
分享
阅读11911
更新时间2022-04-11
@Entity:声明一个类为数据实体对象;
value:实体名称(数据库表名称),默认采用当前类名称;
@Entity("tb_demo")
public class Demo {
//...
}@Id:声明一个类成员为主键;
无参数,配合@Property注解使用;
@Entity("tb_demo")
public class Demo {
@Id
@Property
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}@Property:声明一个类成员为数据实体属性;
name:实现属性名称,默认采用当前成员名称;
autoincrement:是否为自动增长,默认为false;
sequenceName:序列名称,适用于类似Oracle等数据库,配合autoincrement参数一同使用;
nullable:允许为空,默认为true;
unsigned:是否为无符号,默认为false;
length:数据长度,默认0为不限制;
decimals:小数位数,默认0为无小数;
type:数据类型,默认为Type.FIELD.VARCHAR;
@Entity("tb_user")
public class User {
@Id
@Property
private String id;
@Property(name = "user_name",
nullable = false,
length = 32)
private String username;
@Property(name = "age",
unsigned = true,
type = Type.FIELD.INT)
private Integer age;
// 省略Get/Set方法...
}@PK:声明一个类为某数据实体的复合主键对象;
无参数;
@PK
public class UserExtPK {
@Property
private String uid;
@Property(name = "wx_id")
private String wxId;
// 省略Get/Set方法...
}
@Entity("tb_user_ext")
public class UserExt {
@Id
private UserExtPK id;
@Property(name = "open_id",
nullable = false,
length = 32)
private String openId;
// 省略Get/Set方法...
}@Readonly:声明一个成员为只读属性,数据实体更新时其将被忽略;
无参数,配合@Property注解使用;
@Entity("tb_demo")
public class Demo {
@Id
@Property
private String id;
@Property(name = "create_time")
@Readonly
private Date createTime;
// 省略Get/Set方法...
}@Indexes:声明一组数据实体的索引;
@Index:声明一个数据实体的索引;
@Comment:注释内容;
@Default:为一个成员属性或方法参数指定默认值;
看着这么多的注解,是不是觉得编写实体很麻烦呢,不要急,框架提供了自动生成实体的方法,往下看:)
注:上面注解或注解参数中有一些是用于未来能通过实体对象直接创建数据库表结构(以及SQL脚本文件)的,可以暂时忽略;
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
共5课时
17.2万人学习
共49课时
77万人学习
共29课时
61.7万人学习
共25课时
39.3万人学习
共43课时
71万人学习
共25课时
61.6万人学习
共22课时
23万人学习
共28课时
33.9万人学习
共89课时
125万人学习