ideaJPA实现mysql_idea 从数据库快速生成Spring Data JPA实体类

第一步,调出 Persistence 窗口.

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

L3Byb3h5L2h0dHBzL2dpdGh1Yi5jb20vaXRndWFuZy93ZWl4aW5fc2VsbC9yYXcvbWFzdGVyL3dlaXhpbl9zZWxsL2ltYWdlcy8yLnBuZw==.jpg

第二步:打开 Persistence窗口

L3Byb3h5L2h0dHBzL2dpdGh1Yi5jb20vaXRndWFuZy93ZWl4aW5fc2VsbC9yYXcvbWFzdGVyL3dlaXhpbl9zZWxsL2ltYWdlcy8zLnBuZw==.jpg

配置 生成实体类的参数

L3Byb3h5L2h0dHBzL2dpdGh1Yi5jb20vaXRndWFuZy93ZWl4aW5fc2VsbC9yYXcvbWFzdGVyL3dlaXhpbl9zZWxsL2ltYWdlcy80LnBuZw==.jpg

如图:

1.数据源,即链接数据库的信息,按要求填写数据库信息即可

2.生成实体类的位置.

3.实体类名称前缀.这里我什么都没写.

4.实体类名称后缀. 这里我写Entity. 比如数据库表名为 user,那么生成实体类为 UserEntity

5.选择哪些表的哪些字段生成实体类.这里我全选.

6.生成的实体类自动添加 JPA注解.

最后点击ok,就能在我们的项目下看到生成的实体类

L3Byb3h5L2h0dHBzL2Jsb2cuY3Nkbi5uZXQvaXRndWFuZ2l0L2FydGljbGUvZGV0YWlscy9pbWFnZXMvNS5wbmc=.jpg

如:

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;

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值