generatorConfig.properties --> resource文件夹下
# 数据库驱动jar 路径
drive.class.path=/Users/mac/.m2/repository/mysql/mysql-connector-java/5.1.30/mysql-connector-java-5.1.30.jar
# 数据库连接参数
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&connectionCollation=utf8mb4_bin&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&transformedBitIsBoolean=true
jdbc.username=root
jdbc.password=root
# 包路径配置
model.package=me.wanghui.comm.domain
dao.package=me.wanghui.service.mapper
xml.mapper.package=me.wanghui.service.mapper
target.project=src/test/java
generatorConfig.xml --> resource文件夹下
<?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">
<!--配置Run As Maven build : Goals参数: mybatis-generator:generate -Dmybatis.generator.overwrite=true -->
<!--配置tableName,使用Run As Maven build生成dao model层-->
<generatorConfiguration>
<!--配置文件路径-->
<properties url="${mybatis.generator.generatorConfig.properties}" />
<!--<properties url="./src/test/resources/generatorConfig.properties"/>-->
<!--数据库驱动包路径-->
<classPathEntry location="${drive.class.path}" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<!--关闭注释-->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接信息-->
<jdbcConnection driverClass="${jdbc.driver}" connectionURL="${jdbc.url}" userId="${jdbc.username}"
password="${jdbc.password}">
</jdbcConnection>
<!--生成的model包路径-->
<javaModelGenerator targetPackage="${model.package}" targetProject="${target.project}">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成xml mapper文件路径-->
<sqlMapGenerator targetPackage="${xml.mapper.package}" targetProject="${target.project}">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--生成的Dao接口的包路径-->
<javaClientGenerator type="XMLMAPPER" targetPackage="${dao.package}" targetProject="${target.project}">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!--对应数据库表名-->
<!--<table tableName="user">-->
<!--</table>-->
<!--对应数据库表名,生成的代码不包含Example查询方式-->
--><table schema="general" tableName="user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="true"/>
</table>
</context>
</generatorConfiguration>
pom.xml 文件生成器部分
<!--指明生成器版本及配置文件目录-->
<properties>
<plugin.mybatis.generator>1.3.2</plugin.mybatis.generator>
<mybatis.generator.generatorConfig.xml>${basedir}/src/main/resources/generatorConfig.xml</mybatis.generator.generatorConfig.xml>
<mybatis.generator.generatorConfig.properties>file:///${basedir}/src/main/resources/generatorConfig.properties</mybatis.generator.generatorConfig.properties>
</properties>
<!--build 配置-->
<build>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${plugin.mybatis.generator}</version>
<configuration>
<configurationFile>${mybatis.generator.generatorConfig.xml}</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</build>
配置完成后点击Intellij右侧边栏的 Maven Projects,选择pom文件所在的项目,选择Plugins,就能看到代码生成器了