MyEclipse使用MyBatis Generator 工具逆向生成對映檔案
阿新 • • 發佈:2019-02-09
下載mybatis generator外掛
將features、plugins拷貝到myeclipse10下的dropins資料夾中,如下圖所示,重啟myeclipse。
以下以mysql為例逆向生成對映檔案,其中資料庫為test表為userinfo,id欄位自增。
建立一新的web project mybatis_generator,並新增sql驅動jar包。
在src中建立一個MyBatis生成orm檔案的配置檔案,單擊next,保持預設設定finish即可。
對生成的generatorConfig.xml檔案進行更改。
注:context id、targetProject均為專案名稱,generatorKey標籤配置id欄位自增。<?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 > <context id="mybatis_generator" > <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="root" /> <javaModelGenerator targetPackage="orm" targetProject="mybatis_generator" /> <sqlMapGenerator targetPackage="orm" targetProject="mybatis_generator" /> <javaClientGenerator targetPackage="orm" targetProject="mybatis_generator" type="XMLMAPPER" /> <table schema="test" tableName="userinfo" > <generatedKey column="id" sqlStatement="mysql" identity="true" /> </table> </context> </generatorConfiguration>
右鍵配置檔案,選擇Generator MyBatis/iBATIS Artifacts即可生成orm對映檔案