JPA常用注解

话不多说上代码:

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 + '\'' +
                '}';
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值