Mybatis-generator的使用
下载eclipse插件Mybatis-generator,解压,放到eclipse安装目录,覆盖features,plugins,重启eclipse。
编写自动生成需要的配置文件:
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEgeneratorConfiguration PUBLIC"-//mybatis.org//DTDMyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntrylocation="D:/workspace/MybatisTest/WebContent/WEB-INF/lib/db2java.jar"/>
<classPathEntrylocation="D:/workspace/MybatisTest/WebContent/WEB-INF/lib/db2jcc.jar"/>
<classPathEntrylocation="D:/workspace/MybatisTest/WebContent/WEB-INF/lib/db2jcc_license_cu.jar"/>
<contextid="context1">
<jdbcConnectiondriverClass="com.ibm.db2.jcc.DB2Driver"
connectionURL="jdbc:db2://192.168.8.10:60020/web"userId="tst_db"
password="tst_db"/>
<javaModelGeneratortargetPackage="com.test.persistence.mybatis.model"
targetProject="MybatisTest"/>
<sqlMapGeneratortargetPackage="com.test.persistence.mybatis.model"
targetProject="MybatisTest"></sqlMapGenerator>
<javaClientGeneratortargetPackage="com.test.persistence.mybatis.model"
targetProject="MybatisTest"type="XMLMAPPER"/>
<tableschema=""tableName="T_O_INF"domainObjectName="TOInf"></table>
<tabletableName="t_o_log"domainObjectName="TOLog"
enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
选中文件,右键,点击“Generate Mybatis….”。ok。所有文件已经自动生成。