采用命令行方式执行逆向工程
1、配置文件generatorConfig.xml 保存在目录:D:\E\workspace\eclipse\mybatis_generator
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEgeneratorConfiguration
PUBLIC"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--jar
<classPathEntrylocation="D:/E/worksoft/apache-maven-3.6.0/repository/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar"/>
<!--jar
<!-- <classPathEntry location="mysql-connector-java-8.0.11.jar" /> -->
<!-- id:-->
<contextid="DB2Tables"targetRuntime="MyBatis3">
<commentGenerator>
<!-- false:-->
<!-- -->
<propertyname="suppressDate"value="true"/>
<!-- truefalse:-->
<propertyname="suppressAllComments"value="true"/>
</commentGenerator>
<!---->
<jdbcConnectiondriverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8"
userId="root"
password="(Junli@2018*test)">
</jdbcConnection>
<javaTypeResolver>
<!-- decimalJava sql BigDecimal -->
<!-- double long -->
<!-- sql -->
<!-- This property is used to specify whether MyBatis Generator should
force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields, -->
<propertyname="forceBigDecimals"value="false"/>
</javaTypeResolver>
<!-- -->
<javaModelGeneratortargetPackage="com.mybatis.bean"
targetProject="src/main/java">
<propertyname="enableSubPackages"value="true"/>
<!-- -->
<propertyname="trimStrings"value="true"/>
</javaModelGenerator>
<!-- -->
<sqlMapGeneratortargetPackage="com.mybatis.mapper"
targetProject="src/main/java">
<propertyname="enableSubPackages"value="true"/>
</sqlMapGenerator>
<!-- -->
<javaClientGeneratortype="XMLMAPPER"
targetPackage="com.mybatis.dao"
targetProject="src/main/java">
<propertyname="enableSubPackages"value="true"/>
</javaClientGenerator>
<!-- -->
<tabletableName="mydept"domainObjectName="Department"></table>
<tabletableName="myemployeee"domainObjectName="Employee"></table>
</context>
</generatorConfiguration>
2、将驱动文件mysql-connector-java-8.0.11.jar和逆向工程mybatis-generator-core-1.3.7.jar保存到配置文件同一个目录下
3、命令行执行:
3.1) cd D:\E\workspace\eclipse\mybatis_generator
3.2)
jar包和配置文件在同一目录下执行如下命令:
java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml
jar包和配置文件在非同一目录下可执行如下命令:
java -jar D:\E\worksoft\apache-maven-3.6.0\repository\org\mybatis\generator\mybatis-generator-core\1.3.7\mybatis-generator-core-1.3.7.jar -configfile D:\E\workspace\eclipse\mybatis_generator\src\main\resources\generatorConfig.xml
4、生成的文件在配置的src/main/java目录下,即D:\E\workspace\eclipse\mybatis_generator\src\main\java目录下
5存在问题:
1)驱动包找不到,配置驱动包
<!--指定驱动文件,否则提示驱动不存在, jar包与配置文件非同一路径情况下使用绝对路径-->
<classPathEntry location="D:/E/worksoft/apache-maven-3.6.0/repository/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar"/>
<!--jar包与配置文件同一路径情况下-->
<!-- <classPathEntry location="mysql-connector-java-8.0.11.jar" /> -->
2) connectionURL 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾
xml对&支持不好,采用&转义代替&
参考:https://blog.csdn.net/qq_33229669/article/details/82227213