溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

發(fā)布時(shí)間:2020-08-30 01:09:35 來源:腳本之家 閱讀:410 作者:走過程序員的路 欄目:編程語言

本篇博客記錄下 IDEA 中連接數(shù)據(jù)庫反轉(zhuǎn)生成 Hibernate 實(shí)體和配置文件。

1. 打開 DataBase 窗口,添加數(shù)據(jù)源

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

到了這一步數(shù)據(jù)源已添加好。

2. 添加 hibernat 持久層支持,生成實(shí)體 Bean /配置文件,這一步要去plugs那里下載一個(gè)hibernate插件,不然你的persistence是出不來的

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

idea hibernate jpa 生成實(shí)體類的實(shí)現(xiàn)

然后選擇數(shù)據(jù)源,選擇包,添加生成 Bean 的后綴,選擇表,選擇生成 xml 配置文件還是注解。

OK,結(jié)束

如果你選擇生成帶 JPA 注解類,映射文件是可以省略的,相反如果你生成映射文件,JPA 注解也可以省略。

看你喜歡哪種方式

生成注解例子

@Entity
@Table(name = "user", schema = "db_test", catalog = "")
public class UserPO {
  private String uuid;
  private String name;
  private String passwd;
  private String sex;
  private Timestamp birthday;
  private String phone;
  private String photo;
  private String email;
  private String yxbz;
  private String sorts;
 
  @Id
  @Column(name = "UUID")
  public String getUuid() {
    return uuid;
  }
 
  public void setUuid(String uuid) {
    this.uuid = uuid;
  }
 
  @Basic
  @Column(name = "NAME")
  public String getName() {
    return name;
  }
 
  public void setName(String name) {
    this.name = name;
  }
 
  @Basic
  @Column(name = "PASSWD")
  public String getPasswd() {
    return passwd;
  }
 
  public void setPasswd(String passwd) {
    this.passwd = passwd;
  }
 
  @Basic
  @Column(name = "SEX")
  public String getSex() {
    return sex;
  }
 
  public void setSex(String sex) {
    this.sex = sex;
  }
 
  @Basic
  @Column(name = "BIRTHDAY")
  public Timestamp getBirthday() {
    return birthday;
  }
 
  public void setBirthday(Timestamp birthday) {
    this.birthday = birthday;
  }
 
  @Basic
  @Column(name = "PHONE")
  public String getPhone() {
    return phone;
  }
 
  public void setPhone(String phone) {
    this.phone = phone;
  }
 
  @Basic
  @Column(name = "PHOTO")
  public String getPhoto() {
    return photo;
  }
 
  public void setPhoto(String photo) {
    this.photo = photo;
  }
 
  @Basic
  @Column(name = "EMAIL")
  public String getEmail() {
    return email;
  }
 
  public void setEmail(String email) {
    this.email = email;
  }
 
  @Basic
  @Column(name = "YXBZ")
  public String getYxbz() {
    return yxbz;
  }
 
  public void setYxbz(String yxbz) {
    this.yxbz = yxbz;
  }
 
  @Basic
  @Column(name = "SORTS")
  public String getSorts() {
    return sorts;
  }
 
  public void setSorts(String sorts) {
    this.sorts = sorts;
  }
 
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
 
    UserPO userPO = (UserPO) o;
 
    if (uuid != null ? !uuid.equals(userPO.uuid) : userPO.uuid != null) return false;
    if (name != null ? !name.equals(userPO.name) : userPO.name != null) return false;
    if (passwd != null ? !passwd.equals(userPO.passwd) : userPO.passwd != null) return false;
    if (sex != null ? !sex.equals(userPO.sex) : userPO.sex != null) return false;
    if (birthday != null ? !birthday.equals(userPO.birthday) : userPO.birthday != null) return false;
    if (phone != null ? !phone.equals(userPO.phone) : userPO.phone != null) return false;
    if (photo != null ? !photo.equals(userPO.photo) : userPO.photo != null) return false;
    if (email != null ? !email.equals(userPO.email) : userPO.email != null) return false;
    if (yxbz != null ? !yxbz.equals(userPO.yxbz) : userPO.yxbz != null) return false;
    if (sorts != null ? !sorts.equals(userPO.sorts) : userPO.sorts != null) return false;
 
    return true;
  }
 
  @Override
  public int hashCode() {
    int result = uuid != null ? uuid.hashCode() : 0;
    result = 31 * result + (name != null ? name.hashCode() : 0);
    result = 31 * result + (passwd != null ? passwd.hashCode() : 0);
    result = 31 * result + (sex != null ? sex.hashCode() : 0);
    result = 31 * result + (birthday != null ? birthday.hashCode() : 0);
    result = 31 * result + (phone != null ? phone.hashCode() : 0);
    result = 31 * result + (photo != null ? photo.hashCode() : 0);
    result = 31 * result + (email != null ? email.hashCode() : 0);
    result = 31 * result + (yxbz != null ? yxbz.hashCode() : 0);
    result = 31 * result + (sorts != null ? sorts.hashCode() : 0);
    return result;
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI