启动类
public class MybatisGenUitls {
private static final Logger logger = LoggerFactory.getLogger(MybatisGenUitls.class);
public static void main(String[] args){
// 执行中的异常信息会保存在warnings中
List<String> warnings = new ArrayList<String>();
try {
// true:生成的文件覆盖之前的
boolean overwrite = true;
// 读取配置,构造 Configuration 对象.
// 如果不想使用配置文件的话,也可以直接来 new Configuration(),然后给相应属性赋值.
File configFile = new File("src/main/resources/myBatisGenerator/generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
logger.error("=======================");
myBatisGenerator.generate(null);
logger.error("=============结束==========");
if(!warnings.isEmpty()){
for (String warning : warnings) {
System.out.println(warning);
}
}
} catch (Exception e) {
logger.error(e.getMessage(),e);
}
}
}
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>
<context id="MysqlContext" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<commentGenerator>
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@1.1.1.1:1521:cmcdb2"
userId="xxx"
password="xxx">
</jdbcConnection>
<javaModelGenerator targetPackage="com.ai.coms.asmt.bo" targetProject=".\src\main\java"/>
<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources\mybatis"/>
<javaClientGenerator targetPackage="com.ai.coms.interfaces" targetProject=".\src\main\java" type="XMLMAPPER"/>
<!-- sql占位符,表示所有的表 -->
<table tableName="WB_ASMT_TASK_KPI_RESULT"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
</table>
</context>
</generatorConfiguration>