第一步:下载MyBatis的Generator工具
下载地址:http://code.google.com/p/mybatis/downloads/detail?name=mybatis-generator-core-1.3.1-bundle.zip&can=3&q=Product%3DGenerator
第二步:配置自动生成代码所需的XML配置文件,例如(generator.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:数据库的JDBC驱动,换成你自己的驱动位置 -->
- <classPathEntry location="D:\libs\ojdbc14.jar" />
- <context id="DB2Tables" targetRuntime="MyBatis3">
- <!-- 去除自动生成的注释 -->
- <commentGenerator>
- <property name="suppressAllComments" value="true" />
- </commentGenerator>
- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@172.16.88.10:1521:mydb" userId="abc" password="abc">
- </jdbcConnection>
- <javaTypeResolver >
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <!-- targetProject:自动生成代码的位置 -->
- <javaModelGenerator targetPackage="com.test.model" targetProject="E:\eclipse 3.5.2\workspace\gao\src">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <sqlMapGenerator targetPackage="com.test.mapping" targetProject="E:\eclipse 3.5.2\workspace\gao\src">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao" targetProject="E:\eclipse 3.5.2\workspace\gao\src">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
- <table tableName="pds_system_item" domainObjectName="PdsSystemItem" />
- <table tableName="pds_system_level" domainObjectName="PdsSystemLevel" />
- </context>
- </generatorConfiguration>
将这个文件保存至你下载的mybatis-generator-core-1.3.1文件夹下
第三步:用命令行运行(记得选择自己的文件地址)