话不多说上代码:
package domain;
import javax.persistence.*;
/**
* @Entity :指定当前类是实体类
* @Table :实体类和表之间的对应关系
* name属性:指定数据库中表的名称
*/
@Entity
@Table
public class Address {
/**
* @Id :设置当前属性为主键
* @GeneratedValue :设置主键生成策略
* strategy = GenerationType.IDENTITY 自增 用于MySQL
* strategy = GenerationType.SEQUENCE 序列 用于oracle
* strategy = GenerationType.TABLE jpa自带的一种机制,通过表的形式完成主键自增
* strategy = GenerationType.AUTO 程序自动帮助我们选择
*@Column :指定实体类和表的对应关系
* name:指定数据库表的列名
* unique:是否唯一
* nullable:是否可以为空
* inserttable:是否可以插入
* updatetable:是否可以更新
*还有一些@ManyToOne@OneToMany@OneToOne@JsonIgnore等等
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
private String description;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "Address{" +
"id=" + id +
", description='" + description + '\'' +
'}';
}
}