步骤:
1. 新建generateConfig.xml文件,指定相关路径与名称
2. 引入mybatis-generator-core-1.3.2.jar、mysql-connector-java-5.1.30.jar、ojdbc6-1.0.0.0.jar
3. 新建bat文件,或命令行输入命令,或通过eclipse下载MyBatis的Generate插件,执行generateConfig.xml。
generateConfig.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="mysql-connector-java-5.1.30.jar"></classPathEntry>
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 指定生成的java文件的编码,没有直接生成到项目时中文可能会乱码 -->
<property name="javaFileEncoding" value="UTF-8"/>
<!-- 这里的type里写的是你的实现类的类全路径 -->
<commentGenerator type="org.mybatis.generator.MyCommentGenerator">
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="false"/>
</commentGenerator>
<!-- 指定数据库地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.29.105:3306/ldcar_jeecg?characterEncoding=UTF-8" userId="lduser" password="123456">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--指定实体类路径-->
<javaModelGenerator targetPackage="com.guoyicap.loan.model" targetProject="../../../java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--指定Mapper.xml路径-->
<sqlMapGenerator targetPackage="mapping/loan/" targetProject="../../../resources/META-INF">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 指定Mapper.java路径-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.guoyicap.loan.mapper" targetProject="../../../java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 指定表、实体类名、是否自动生成部分方法-->
<table tableName="ldcar_traffic" domainObjectName="LdcarTraffic" enableCountByExample="true"
enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
</table>
</context>
</generatorConfiguration>
bat文件
@echo -----------------------------------------------------------------------------
@echo Mybatis 代码生成器
@echo -----------------------------------------------------------------------------
@rem 设置变量,获取当前目录
set dir=%cd%
@echo 当前目录%dir%
@echo 开始生成代码
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite
@pause