(IDEA) 从数据库快速生成Spring Data JPA实体类
第一步:配置数据源
第二步:调出 Persistence 窗口
File -> Project Structure -> model -> + -> JPA
-
1.数据源,即链接数据库的信息,按要求填写数据库信息即可
-
2.生成实体类的位置.
-
3.实体类名称前缀.这里我什么都没写.
-
4.实体类名称后缀. 这里我写Entity. 比如数据库表名为 user,那么生成实体类为 UserEntity
-
5.选择哪些表的哪些字段生成实体类.这里我全选.
-
6.生成的实体类自动添加 JPA注解.
最后生成的实体类:
package com.zyu.ares.pojo; import javax.persistence.*; import java.sql.Timestamp; import java.util.Objects; /** * 功能描述 * * @author: zyu * @description: * @date: 2019/8/5 17:21 */ @Entity @Table(name = "t_user", schema = "Ares", catalog = "") public class User { private Integer useId; private String usePhone; private String useCid; private Integer useState; private String useOpenid; private String useMemo; private Timestamp useCreateTime; private Timestamp useUpdateTime; private Timestamp useLastTime; @Id @Column(name = "use_id", nullable = false) public Integer getUseId() { return useId; } public void setUseId(Integer useId) { this.useId = useId; } @Basic @Column(name = "use_phone", nullable = false, length = 20) public String getUsePhone() { return usePhone; } public void setUsePhone(String usePhone) { this.usePhone = usePhone; } @Basic @Column(name = "use_cid", nullable = true, length = 0) public String getUseCid() { return useCid; } public void setUseCid(String useCid) { this.useCid = useCid; } @Basic @Column(name = "use_state", nullable = true) public Integer getUseState() { return useState; } public void setUseState(Integer useState) { this.useState = useState; } @Basic @Column(name = "use_openid", nullable = true, length = 100) public String getUseOpenid() { return useOpenid; } public void setUseOpenid(String useOpenid) { this.useOpenid = useOpenid; } @Basic @Column(name = "use_memo", nullable = true, length = 255) public String getUseMemo() { return useMemo; } public void setUseMemo(String useMemo) { this.useMemo = useMemo; } @Basic @Column(name = "use_create_time", nullable = true) public Timestamp getUseCreateTime() { return useCreateTime; } public void setUseCreateTime(Timestamp useCreateTime) { this.useCreateTime = useCreateTime; } @Basic @Column(name = "use_update_time", nullable = true) public Timestamp getUseUpdateTime() { return useUpdateTime; } public void setUseUpdateTime(Timestamp useUpdateTime) { this.useUpdateTime = useUpdateTime; } @Basic @Column(name = "use_last_time", nullable = true) public Timestamp getUseLastTime() { return useLastTime; } public void setUseLastTime(Timestamp useLastTime) { this.useLastTime = useLastTime; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; User user = (User) o; return Objects.equals(useId, user.useId) && Objects.equals(usePhone, user.usePhone) && Objects.equals(useCid, user.useCid) && Objects.equals(useState, user.useState) && Objects.equals(useOpenid, user.useOpenid) && Objects.equals(useMemo, user.useMemo) && Objects.equals(useCreateTime, user.useCreateTime) && Objects.equals(useUpdateTime, user.useUpdateTime) && Objects.equals(useLastTime, user.useLastTime); } @Override public int hashCode() { return Objects.hash(useId, usePhone, useCid, useState, useOpenid, useMemo, useCreateTime, useUpdateTime, useLastTime); } }