第一步,调出 Persistence 窗口.

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

第二步:打开 Persistence窗口

配置 生成实体类的参数

如图:

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

  • 2.生成实体类的位置.

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

  • 4.实体类名称后缀. 这里我写Entity. 比如数据库表名为 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 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;
}
}
 

idea 从数据库快速生成Spring Data JPA实体类的更多相关文章

  1. Spring Data JPA实体详解

    1. Spring Data JPA实体概述 JPA提供了一种简单高效的方式来管理Java对象(POJO)到关系数据库的映射,此类Java对象称为JPA实体或简称实体.实体通常与底层数据库中的单个关系 ...

  2. SpringBoot入门 (五) 数据库访问之spring data jpa

    本文记录学习使用spring data jpa访问数据库 一 什么是Spring Data JPA JPA(Java Persistence API)是Sun官方提出的Java持久化规范.它为Java ...

  3. 数据库链接 mybatis spring data jpa 两种方式

    jdbc mybatis                     spring data jpa dao service webservice jaxrs     jaxws  springmvc w ...

  4. spring data jpa实体类映射配置

    @Entity:用来标志实体类,知名这是一个和数据库表映射的实体类 @Id注解指明这个属性映射为数据库的主键 @GeneratedValue注解默认使用主键生成方式为自增,hibernate会自动生成 ...

  5. Spring Data JPA实体的生命周期总结

    目录 四种状态 API示例 persist remove merge refresh 参考链接 四种状态 首先以一张图,简单介绍写实体生命周期中四种状态之间的转换关系: 瞬时(New):瞬时对象,刚N ...

  6. Spring Data Jpa 入门学习

    本文主要讲解 springData Jpa 入门相关知识, 了解JPA规范与Jpa的实现,搭建springboot+dpringdata jpa环境实现基础增删改操作,适合新手学习,老鸟绕道~ 1. ...

  7. Spring Data JPA笔记

    1. Spring Data JPA是什么 Spring Data JPA是Spring Data大家族中的一员,它对对持久层做了简化,用户只需要声明方法的接口,不需要实现该接口,Spring Dat ...

  8. SpringBoot学习笔记:Spring Data Jpa的使用

    更多请关注公众号 Spring Data Jpa 简介 JPA JPA(Java Persistence API)意即Java持久化API,是Sun官方在JDK5.0后提出的Java持久化规范(JSR ...

  9. 用Spring Data JPA 基于内存存储pojo的简单案例

    poject结构如下: Customer.java类是一个pojo类,代码如下: package hello; import javax.persistence.Entity; import java ...

随机推荐

  1. Voltage Keepsake CodeForces - 801C(思维)

    题意: 有n台机器,第i台机器每个单位时间消耗ai的功率,初始有bi的功率储备,有一个充电器每个单位时间充p单位的功率 问经过多长时间才能有一个功率位0的机器,如果能够无限使用输出-1: 解析: 时间 ...

  2. MT【173】齐次消元单变量

    已知$x\ge0,x^2+(y-2)^2=1,W=\dfrac{3x^2+2\sqrt{3}xy+5y^2}{x^2+y^2}$,求$W$的最值. 提示:$x\ne0$时,设$t=\dfrac{y}{ ...

  3. 解题:SCOI 2007 蜥蜴

    题面 拆点跑最大流 所有能跑出去的点连向汇点,容量为inf 原点连向所有初始有蜥蜴的点,容量为1 每根柱子拆成两个点“入口”和“出口”,入口向出口连容量为高度的边,出口向别的有高度的柱子的入口连容量为 ...

  4. (转)win下修改jdk环境变量后,java版本不变 java -version

    背景:在windows下安装了多个版本的jdk,发现修改环境变量无法切换. win 7环境下修改JAVA_HOME后,在命令行执行:java -version 发现版本没有变化,以为需要重启才行,就把 ...

  5. bug5 Debug:This kind of launch is configured to openthe debug perspective when it解决办法

    启动tomcat时,myeclipse报错: This kind of launch is configured to openthe debug perspective when itsuspend ...

  6. Redis在window上安装

    转:https://www.cnblogs.com/M-LittleBird/p/5902850.html 在windows上启动RabbitMQ: 这是Redis的启动,需要制定配置文件,否则连接不 ...

  7. 20145215卢肖明《网络对抗》逆向及Bof基础

    20145215卢肖明<网络对抗>逆向及Bof基础 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任 ...

  8. angularJs实现动态增加输入框

    摘要:首先,有一个这样的需求,就是说,我点击添加,会动态出现需要输入的输入框.我们需要定义一个对象,类似这种, {spc:{},spctions:[]} 意思是spc对应的是一个对象,spctions ...

  9. vim文本删除方法 Linux

    1,先打开某个文件: vim   filename 2,转到文件结尾 在命令模式输入 G 3,转到10行 在命令模式输入 10G 4,删除所有内容:先用G 转到文件尾,然后使用下面命令: :1, .d ...

  10. scala 基础到高阶

    本文打算对这小段时间学习 scala 以及 spark 编程技术做个小结,一来温故而知新,而来为以后查阅方便 spark scala 入门小例子  文本文件 UserPurchaseHistory.c ...