idea 從數據庫快速生成Spring Data JPA實體類

第一步,調出 Persistence 窗口.

File—>Project Structure—>model—> + —>JPAjava

第二步:打開 Persistence窗口

配置 生成實體類的參數

如圖:spring

  • 1.數據源,即連接數據庫的信息,按要求填寫數據庫信息便可sql

  • 2.生成實體類的位置.數據庫

  • 3.實體類名稱前綴.這裏我什麼都沒寫.markdown

  • 4.實體類名稱後綴. 這裏我寫Entity. 好比數據庫表名爲 user,那麼生成實體類爲 UserEntityide

  • 5.選擇哪些表的哪些字段生成實體類.這裏我全選.post

  • 6.生成的實體類自動添加 JPA註解.flex

最後點擊ok,就能在咱們的項目下看到生成的實體類

如:this

package com.itguang.weixinsell.entity; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import java.sql.Timestamp; /** * @author itguang * @create 2017-11-25 14:02 **/ @Entity @Table(name = "product_category", schema = "sell", catalog = "") public class ProductCategoryEntity { private int categoryId; private String categoryName; private int categoryType; private Timestamp createTime; private Timestamp updateTime; @Id @Column(name = "category_id") public int getCategoryId() { return categoryId; } public void setCategoryId(int categoryId) { this.categoryId = categoryId; } @Basic @Column(name = "category_name") public String getCategoryName() { return categoryName; } public void setCategoryName(String categoryName) { this.categoryName = categoryName; } @Basic @Column(name = "category_type") public int getCategoryType() { return categoryType; } public void setCategoryType(int categoryType) { this.categoryType = categoryType; } @Basic @Column(name = "create_time") public Timestamp getCreateTime() { return createTime; } public void setCreateTime(Timestamp createTime) { this.createTime = createTime; } @Basic @Column(name = "update_time") public Timestamp getUpdateTime() { return updateTime; } public void setUpdateTime(Timestamp updateTime) { this.updateTime = updateTime; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ProductCategoryEntity that = (ProductCategoryEntity) o; if (categoryId != that.categoryId) return false; if (categoryType != that.categoryType) return false; if (categoryName != null ? !categoryName.equals(that.categoryName) : that.categoryName != null) return false; if (createTime != null ? !createTime.equals(that.createTime) : that.createTime != null) return false; if (updateTime != null ? !updateTime.equals(that.updateTime) : that.updateTime != null) return false; return true; } @Override public int hashCode() { int result = categoryId; result = 31 * result + (categoryName != null ? categoryName.hashCode() : 0); result = 31 * result + categoryType; result = 31 * result + (createTime != null ? createTime.hashCode() : 0); result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0); return result; } } 
相關文章
相關標籤/搜索