jar准备,连接驱动与生成jar
只需要这两个jar的原因很简单,MySQL驱动直接去探测库,生成jar直接拼接生成对应的SQL即可。一个是探测一个去生成。就2个jar就够了
外部生成不同于maven配置,需要手动指定MySQL驱动jar在哪里
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="D:\Ggenerator\mysql-connector-java-5.1.34.jar" />
<context id="mysqlTables" targetRuntime="MyBatis3">
<!--数据源配置-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql:///web_test?characterEncoding=utf-8"
userId="root"
password=""/>
<!--指定生成的类型为java类型,避免数据库中number等类型字段 -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--自动生成的实体的存放包路径 类 -->
<javaModelGenerator targetPackage="com.kaige123.daomu.dao"
targetProject="D:\Ggenerator\src\main\java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--自动生成的*Mapper.xml文件存放路径 -->
<sqlMapGenerator targetPackage="com.kaige123.daomu.dao"
targetProject="D:\Ggenerator\src\main\resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--自动生成的*Mapper.java存放路径 接口 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.kaige123.daomu.dao"
targetProject="D:\Ggenerator\src\main\java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--table表格的配置
tableName表格名称 domainObjectName实例名称 Example是否生成表达式-->
<table tableName="test01" domainObjectName="test01Table"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="log" domainObjectName="logTable"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
</table>
</context>
</generatorConfiguration>
准备包,如果包不存在,则包找不到包错误,生成肯定是没有文件了
运行jar,jar传命令:
java -jar D:\Ggenerator\mybatis-generator-core-1.3.5.jar -configfile D:\Ggenerator\generatorConfig.xml -overwrite
pause
在Windows运行的,pause让终端处于暂停状态,否则运行后一闪而过,结果是什么都不知道。
传递参数为生成config.xml在哪里,-o应该是按照指定的位置去输出