pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.huashen</groupId>
<artifactId>generator</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- mybatis逆向工程 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!--配置文件的位置-->
<!--<configurationFile>src/main/resources/GeneratorConfig.xml</configurationFile>-->
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
</project>
--------------------------
GeneratorConfig.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<properties resource="db.properties"></properties>
<classPathEntry location="${db.localtion}" />
<context id="context1" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 去除自动生成的注释 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 数据库连接配置 -->
<jdbcConnection driverClass="${db.driver}"
connectionURL="${db.url}"
userId="${db.name}"
password="${db.password}" />
<!--jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test"
userId="root"
password="mysql" /-->
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 实体,默认存放在src目录下 -->
<javaModelGenerator targetPackage="com.huashen.pojo"
targetProject="src/main/java" />
<!-- sqlMapper.xml,默认存放在src目录下 -->
<sqlMapGenerator targetPackage="com.huashen.mapper"
targetProject="src/main/java" />
<!--IMapper是应用接口的生成信息-->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.huashen.mapper"
targetProject="src/main/java">
</javaClientGenerator>
<!-- 配置表
schema:不用填写
tableName: 表名
enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
去除自动生成的例子
-->
<table schema="" tableName="user" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<!-- <table schema="" tableName="sys_permission" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_role_permission" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_user" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_user_role" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="unit_info" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="unit_type" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>-->
</context>
</generatorConfiguration>
--------------------------------
db.properties:
#MySQL
db.localtion=D:\\dev\\maven\\Repository\\mysql\\mysql-connector-java\\5.1.34\\mysql-connector-java-5.1.34.jar
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/database_springboot
db.name=root
db.password=123456
-----------------------
运行命令:Run-->Edit Configurations打开配置窗口,然后在点击左上角的+号找到Maven。指定名称,工作空间目录及命令,这里不用加mvn,然后确定后保存。
最后点击三角运行即可