IDEA 下 hibernate 反向生成实体和映射文件

IDEA 下 hibernate 反向生成实体和映射文件

选中项目,鼠标右键项目,选择Add Frameworks Support 或者 选中项目+F4

IDEA 下 hibernate 反向生成实体和映射文件_第1张图片


IDEA 下 hibernate 反向生成实体和映射文件_第2张图片

或者 选中项目+F4

IDEA 下 hibernate 反向生成实体和映射文件_第3张图片



现在看resources多了hibernate.cfg.xml

IDEA 下 hibernate 反向生成实体和映射文件_第4张图片

接下来配置hibernate.cfg.xml




  
    
    jdbc:mysql://localhost:3306/disaster_tolerant
    
    com.mysql.jdbc.Driver
    
    root
    
    123456
  

连接你的数据库

IDEA 下 hibernate 反向生成实体和映射文件_第5张图片

在Persistence中右键项目,然后点击Generate Persistence Mapping,选择By Database Schema

IDEA 下 hibernate 反向生成实体和映射文件_第6张图片

勾勾选选的,你懂的

IDEA 下 hibernate 反向生成实体和映射文件_第7张图片

最后生成的pojo文件给  大家 OB一哈

package com.nelsoner.pojo.test;

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

@Entity
@Table(name = "tb_user", schema = "disaster_tolerant", catalog = "")
public class TbUser {
    private long userId;
    private String username;
    private String mobile;
    private String password;
    private Timestamp createTime;

    @Id
    @Column(name = "user_id", nullable = false)
    public long getUserId() {
        return userId;
    }

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

    @Basic
    @Column(name = "username", nullable = false, length = 50)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "mobile", nullable = false, length = 20)
    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @Basic
    @Column(name = "password", nullable = true, length = 64)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "create_time", nullable = true)
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TbUser tbUser = (TbUser) o;

        if (userId != tbUser.userId) return false;
        if (username != null ? !username.equals(tbUser.username) : tbUser.username != null) return false;
        if (mobile != null ? !mobile.equals(tbUser.mobile) : tbUser.mobile != null) return false;
        if (password != null ? !password.equals(tbUser.password) : tbUser.password != null) return false;
        if (createTime != null ? !createTime.equals(tbUser.createTime) : tbUser.createTime != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = (int) (userId ^ (userId >>> 32));
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (mobile != null ? mobile.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        return result;
    }
}

你可能感兴趣的:(javaweb)