其他分享
首页 > 其他分享> > jpa实体类注解

jpa实体类注解

作者:互联网

、JPA各种实体类注解
、@Entity
表示它为实体类,为一张表,标识各个get方法数据库映射字段

@Table 表示它一张表,name 属性可以标识实体类的名字

2、@Id
标识这个字段为id,

@GeneratedValue 标识id 生成策略

GenerationType.AUTO id 自增

3、@Column
映射这个get方法字段为数据库字段

它的属性 name 数据库对应字段的名称

length 数据库对应字段的长度

nullable 数据库对应字段的长度 是否只读

4、@Temporal
Temporal可以设置时间的时间搓

5、@Transient
代表他不是数据库字段

@Entity
@Temporal(TemporalType.TIMESTAMP)
@Id、
@Column(name = "LAST_NAME",length = 50,nullable = false)
@Transient
@GeneratedValue(strategy = GenerationType.AUTO)
@Id

  

@Table(name = "JPA_CUSTOMERS")
@Entity
public class Customer {

    private Integer id;
    private String lastName;
    private String email;
    private Integer age;
    private Date createdTime;
    private Date birth;

    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    @Temporal(TemporalType.DATE)
    public Date getBirth() {
        return birth;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

//    @TableGenerator(name = "ID_GENERATOR",table = "jpa_id_generator",pkColumnName = "PK_NAME",pkColumnValue = "CUSTOMER_ID"
//            ,valueColumnName = "PK_VALUE",allocationSize = 100
//    )
//    @GeneratedValue(strategy = GenerationType.TABLE,generator = "ID_GENERATOR")
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "LAST_NAME",length = 50,nullable = false)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "id=" + id +
                ", lastName='" + lastName + '\'' +
                ", email='" + email + '\'' +
                ", age=" + age +
                ", createdTime=" + createdTime +
                ", birth=" + birth +
                '}';
    }

    @Transient
    public String getInfo(){
        return "lastName"+lastName+"email"+email;
    }
}

 

标签:实体类,return,String,jpa,lastName,id,email,注解,public
来源: https://www.cnblogs.com/akwlovezzy/p/16291101.html