1.准备需要的jar包:mybatis-generator-core-1.3.2.jar、 ojdbc.jar(忽略版本号,这只是我用的jar 版本)
2.新建一个文件,命名:mybatisGenerator.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="F:/software/mybatisGenerator/ojdbc6.jar"/>
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@14.215.113.76:1521:orcl" userId="zh_yx_zcsp"
password="zhwb"/>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="ctas.test.entity"
targetProject="F:/software/mybatisGenerator/src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="ctas.test.entity.xml"
targetProject="F:/software/mybatisGenerator/src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator targetPackage="ctas.test.mapper"
targetProject="F:/software/mybatisGenerator/src" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--<table tableName="T_FEE_AGTBILL" domainObjectName="FeeAgentBill"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"/>-->
<!-- 要生成那些表(更改tableName和domainObjectName就可以)表名中别有空格,否则会报错-->
<table tableName="SERVICE_ITEM" domainObjectName="ServiceItem"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<!--<columnRenamingRule searchString="^D_"
replaceString=""/>-->
</table>
</context>
</generatorConfiguration>
3.打开命令提示符,进入F:\software\mybatisGenerator,输入命令:java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite