溫馨提示×

溫馨提示×

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

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

idea怎么從數(shù)據(jù)庫快速生成Spring Data JPA實體類

發(fā)布時間:2022-10-18 16:07:28 來源:億速云 閱讀:220 作者:iii 欄目:數(shù)據(jù)庫

本篇內(nèi)容主要講解“idea怎么從數(shù)據(jù)庫快速生成Spring Data JPA實體類”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“idea怎么從數(shù)據(jù)庫快速生成Spring Data JPA實體類”吧!

idea 從數(shù)據(jù)庫快速生成Spring Data JPA實體類

第一步,調(diào)出 Persistence 窗口.

File—>Project Structure—>model—> + —>JPA

第二步:打開 Persistence窗口

配置 生成實體類的參數(shù)

  • 1.數(shù)據(jù)源,即鏈接數(shù)據(jù)庫的信息,按要求填寫數(shù)據(jù)庫信息即可

  • 2.生成實體類的位置.

  • 3.實體類名稱前綴.這里我什么都沒寫.

  • 4.實體類名稱后綴. 這里我寫Entity. 比如數(shù)據(jù)庫表名為 user,那么生成實體類為 UserEntity

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

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

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

如:

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
@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

到此,相信大家對“idea怎么從數(shù)據(jù)庫快速生成Spring Data JPA實體類”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

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

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

AI