这个工具mybatis-generator-gui可以说是可以节省很大的时间,可以直接生成Entity,xml以及简单的dao功能,非常的爽,默认会将数据库的下划线命名转化为驼峰命名的方式,所以所是非常的爽,再说你还可以自己更改里面的代码,实现更多功能

项目地址

这个工具,先声明,不是我写的,但是我觉得还是挺不错的,项目地址

https://gitee.com/yellowcong/mybatis-generator-gui

导入项目

1、选择导入

MyBatis之配置文件、Entity生成工具-yellowcong_mybatis

2、选择maven项目

MyBatis之配置文件、Entity生成工具-yellowcong_mybatis_02

3、选择项目路径

MyBatis之配置文件、Entity生成工具-yellowcong_下划线_03

4、找到启动类

MyBatis之配置文件、Entity生成工具-yellowcong_mybatis_04

5、启动工具类

MyBatis之配置文件、Entity生成工具-yellowcong_ide_05

6、到达战场

MyBatis之配置文件、Entity生成工具-yellowcong_mybatis_06

配置数据库

1、数据库连接配置

MyBatis之配置文件、Entity生成工具-yellowcong_mybatis_07

2、代码输出地址配置

MyBatis之配置文件、Entity生成工具-yellowcong_数据库_08

3、生成的代码

MyBatis之配置文件、Entity生成工具-yellowcong_数据库_09

代码

生成的代码目录结构

MyBatis之配置文件、Entity生成工具-yellowcong_mybatis_10

User表

CREATE TABLE `yellowcong_users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `age` int(11) DEFAULT NULL,
  `nick_name` varchar(32) DEFAULT NULL,
  `password` varchar(32) DEFAULT NULL,
  `user_name` varchar(32) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8

实体类

大家会发现,他默认会将下划线命名的方式转化为驼峰的方式,这个非常的好,很适合大家哦

package com.yellowcong.entity;

import java.io.Serializable;

/**
 * @author 
 */
public class User implements Serializable {
    private Integer id;

    private Integer age;

    private String nickName;

    private String password;

    private String userName;

    private static final long serialVersionUID = 1L;

    public Integer getId() {
        return id;
    }

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

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getPassword() {
        return password;
    }

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

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        User other = (User) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getAge() == null ? other.getAge() == null : this.getAge().equals(other.getAge()))
            && (this.getNickName() == null ? other.getNickName() == null : this.getNickName().equals(other.getNickName()))
            && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
            && (this.getUserName() == null ? other.getUserName() == null : this.getUserName().equals(other.getUserName()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getAge() == null) ? 0 : getAge().hashCode());
        result = prime * result + ((getNickName() == null) ? 0 : getNickName().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getUserName() == null) ? 0 : getUserName().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", age=").append(age);
        sb.append(", nickName=").append(nickName);
        sb.append(", password=").append(password);
        sb.append(", userName=").append(userName);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}