1/自动生成的jar包:mybatis-generator-core-1.3.2.jar
2/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>
<classPathEntry location="lib/mysql-connector-5.1.8.jar" />
<context id="MySqlTables" targetRuntime="MyBatis3">
<!--配置数据库链接-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/abcProject?characterEncoding=utf8" userId="root"
password="11112222">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--配置实体bean-->
<javaModelGenerator targetPackage="xmlParer"
targetProject="D:\test\xmlParer">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--配置实体map接口(dao)-->
<sqlMapGenerator targetPackage="xmlParer"
targetProject="D:\test\xmlParer">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--配置实体bean的sql.xml-->
<javaClientGenerator type="XMLMAPPER"
targetPackage="xmlParer"
targetProject="D:\test\xmlParer">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!--配置实体-->
<table tableName="abc_agency" domainObjectName="Agency">
</table>
</context>
</generatorConfiguration>
3.1/ 执行命令
java -jar mybatis-generator-core-1.3.0.jar -configfile D:\test\generatorconfig.xml -overwrite
这样基本就ok了。
3.2 Main方法执行
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("src/generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config;
try {
config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator;
try {
myBatisGenerator = new MyBatisGenerator(config, callback,
warnings);
myBatisGenerator.generate(null);
} catch (Exception e) {
e.printStackTrace();
}
来源:https://www.cnblogs.com/huapox/p/3516398.html