相关文档网址:
1.http://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core/1.3.5
maven代码
2.http://www.mybatis.org/generator/index.html 快速入门(主要关注 快速入门,运行逆向工程,xml标签)
配置步骤:
1.先配置好配置文件,MBG.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="DB2Tables" targetRuntime="MyBatis3">
<!-- 注解配置 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- JDBC配置 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/ssm"
userId="root"
password="">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 逆向工程生成位置 -->
<javaModelGenerator targetPackage="bean" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 制定映射文件 -->
<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 指定接口位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- tablie表生成策略 -->
<table tableName="emp" domainObjectName="Employee"> </table>
<table tableName="dep" domainObjectName="Department"></table>
</context>
</generatorConfiguration>
2.java运行文件
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("mbg.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);