1、配置文件
<?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="jdbc.properties"/>
<!--数据库jar--->
<classPathEntry location="webapp/WEB-INF/lib/mysql-connector-java.jar" />

<context id="context1" defaultModelType="flat" targetRuntime="MyBatis3Simple">
<property name="javaFileEncoding" value="UTF-8"/>

<plugin type="org.mybatis.generator.plugins.CustomerPluginAdapter">
<property name="targetPackage" value="com.charlin.erp.${module}.${package}.service" />
<property name="implementationPackage" value="com.charlin.erp.${module}.${package}.service.impl" />
<property name="controllerPackage" value="com.charlin.erp.${module}.${package}.action" />
<property name="controllerPath" value="${path}" />
<property name="targetProject" value="${module}/src/main/java" />
<property name="generatedSC" value="${generatedSC}" />
</plugin>
<plugin type="org.mybatis.generator.plugins.ExpandPluginAdapter">

</plugin>
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true" />
</commentGenerator>

<jdbcConnection connectionURL="${jdbc.url_main}" driverClass="${jdbc.driver}" password="${jdbc.password}" userId="${jdbc.username}" />
<javaModelGenerator targetPackage="com.charlin.erp.${module}.${package}.model" targetProject="core/src/main/java" />
<sqlMapGenerator targetPackage="com.charlin.erp.${module}.${package}.dao" targetProject="core/src/main/java" />
<javaClientGenerator targetPackage="com.charlin.erp.${module}.${package}.dao" targetProject="core/src/main/java" type="XMLMAPPER" />

<table tableName="${tableName}" domainObjectName="${className}" mapperName="${className}DAO"> </table>
</context>
</generatorConfiguration>

2、运行生成

package com.charlin.erp.common.generator.run;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.util.ArrayList;
import java.util.List;

public class MyBatisGeneratorRun {

public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<String>();

boolean overwrite = true;
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(MyBatisGeneratorRun.class.getResourceAsStream("./generatorConfig.xml"));
DefaultShellCallback callback = new DefaultShellCallback(overwrite);

MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
System.out.println(warnings);
}

}