mybatis-gennerator 自動生成插件可以自動生成項目中所須要的dao、bean、mapper xml文件。java
mybatis-gennerator 的使用主要是generatorConfig.xml 的配置mysql
咱們能夠把編寫好的generatorConfig.xml配置文件放到eclipse下任意項目的下面sql
下面是配置文件的具體內容數據庫
<?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="D:\Util\maven\maven-dependcies\mysql\mysql-connector-java\5.1.35\mysql-connector-java-5.1.35.jar"/> <context id="context1" > <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test" userId="test" password="test" /> <javaModelGenerator targetPackage="com.aspire.comp.esp.common.entity" targetProject="test" /> <sqlMapGenerator targetPackage="com.aspire.comp.esp.common.dao.mysql" targetProject="test" /> <javaClientGenerator targetPackage="com.aspire.comp.esp.common.dao" targetProject="test" type="XMLMAPPER" /> <table schema="test" tableName="a8_company_fre_app_activity" domainObjectName="FreAppActivity" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"> <generatedKey column="id" sqlStatement="mysql" identity="true"/> </table> <table schema="test" tableName="a8_company_fre_weixin_activity" domainObjectName="FreWeiXinActivity" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"> <generatedKey column="id" sqlStatement="mysql" identity="true"/> </table> </context> </generatorConfiguration> 咱們解釋下上面的配置文件 classPathEntry 是本地MySQL鏈接工具的路徑 <context>是一個大目錄 表明一個數據庫 配置文件能夠有多個context context 下面的目錄 jdbcConnection 數據庫地址 javaModelGenerator javaClientGenerator sqlMapGenerator 分別表明的是實體類,Java接口,XML配置文件 targetProject 表明項目名 targetPackage 包路徑 而後table 節點表明數據庫中表的具體映射 tableName 是代表 domainObjectName 是生成的實體類名 enableCountByExample 爲是否生成測試類 項目中通常都是 false generatedKey 是主鍵自動生成(適用於自增)
在generatorConfig.xml 配置文件上右鍵執行 便能自動生成所需的實體類、接口、配置文件了mybatis