idea springboot jpa从数据库表生成实体类

问题引入

最近有个springboot的项目,使用了jpa,表已创建好,需要创建对应实体类,幸运的是idea本来就支持。
idea 有个Tool window 叫作Persistence,可以将数据库表生成实体类:
QQ20180508-105800@2x

如何使用

要使用Persistence窗口需要:
QQ20180508-102100@2x

QQ20180508-102228@2x

QQ20180508-105427@2x

QQ20180508-105453@2x

package net.toocruel.iqismart.entity;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * @Description
 * @Auther sty
 * @createTime 2018/5/8 上午10:51
 */
@Entity
@Table(name = "ask_questions", schema = "tipask", catalog = "")
public class AskQuestionsEntity {
    private int id;
    private int userId;
    private int categoryId;
    private String title;
    private String description;
    private short price;
    private byte hide;
    private int answers;
    private int views;
    private int followers;
    private int collections;
    private int comments;
    private byte device;
    private byte status;
    private Timestamp createdAt;
    private Timestamp updatedAt;

    @Id
    @Column(name = "id")
    public int getId() {
        return id;
    }

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

    @Basic
    @Column(name = "user_id")
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "category_id")
    public int getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

    @Basic
    @Column(name = "title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Basic
    @Column(name = "price")
    public short getPrice() {
        return price;
    }

    public void setPrice(short price) {
        this.price = price;
    }

    @Basic
    @Column(name = "hide")
    public byte getHide() {
        return hide;
    }

    public void setHide(byte hide) {
        this.hide = hide;
    }

    @Basic
    @Column(name = "answers")
    public int getAnswers() {
        return answers;
    }

    public void setAnswers(int answers) {
        this.answers = answers;
    }

    @Basic
    @Column(name = "views")
    public int getViews() {
        return views;
    }

    public void setViews(int views) {
        this.views = views;
    }

    @Basic
    @Column(name = "followers")
    public int getFollowers() {
        return followers;
    }

    public void setFollowers(int followers) {
        this.followers = followers;
    }

    @Basic
    @Column(name = "collections")
    public int getCollections() {
        return collections;
    }

    public void setCollections(int collections) {
        this.collections = collections;
    }

    @Basic
    @Column(name = "comments")
    public int getComments() {
        return comments;
    }

    public void setComments(int comments) {
        this.comments = comments;
    }

    @Basic
    @Column(name = "device")
    public byte getDevice() {
        return device;
    }

    public void setDevice(byte device) {
        this.device = device;
    }

    @Basic
    @Column(name = "status")
    public byte getStatus() {
        return status;
    }

    public void setStatus(byte status) {
        this.status = status;
    }

    @Basic
    @Column(name = "created_at")
    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    @Basic
    @Column(name = "updated_at")
    public Timestamp getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Timestamp updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AskQuestionsEntity that = (AskQuestionsEntity) o;
        return id == that.id &&
                userId == that.userId &&
                categoryId == that.categoryId &&
                price == that.price &&
                hide == that.hide &&
                answers == that.answers &&
                views == that.views &&
                followers == that.followers &&
                collections == that.collections &&
                comments == that.comments &&
                device == that.device &&
                status == that.status &&
                Objects.equals(title, that.title) &&
                Objects.equals(description, that.description) &&
                Objects.equals(createdAt, that.createdAt) &&
                Objects.equals(updatedAt, that.updatedAt);
    }

    @Override
    public int hashCode() {

        return Objects.hash(id, userId, categoryId, title, description, price, hide, answers, views, followers, collections, comments, device, status, createdAt, updatedAt);
    }
}

(全文完)

(转载本站文章请注明作者和出处 idea springboot jpa从数据库表生成实体类