天天看點

mybatis generator 配置 反向生成Entity簡單增删改查

<?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>
  <!--資料庫驅動jar -->
  <classPathEntry location="D:\.m2\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" />

  <context id="DB2Tables" targetRuntime="MyBatis3">
    <!--去除注釋 -->
    <commentGenerator>
      <property name="suppressAllComments" value="true" />
    </commentGenerator>

    <!--資料庫連接配接 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.5.159:3306/資料庫名稱"
      userId="使用者名" password="你懂得">
    </jdbcConnection>
    <!--預設false Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC. -->
    <javaTypeResolver>
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>

    <!--生成實體類 指定包名 以及生成的位址 (可以自定義位址,但是路徑不存在不會自動建立 使用Maven生成在target目錄下,會自動建立) -->
    <javaModelGenerator targetPackage="com.heaboy.包名.base.entity" targetProject="項目名">
      <property name="enableSubPackages" value="false" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>
    <!--生成SQLMAP檔案 -->
    <sqlMapGenerator targetPackage="com.heaboy.包名.mybatis" targetProject="項目名">
      <property name="enableSubPackages" value="false" />
    </sqlMapGenerator>
    <!--生成Dao檔案 可以配置 type="XMLMAPPER"生成xml的dao實作 context id="DB2Tables" 修改targetRuntime="MyBatis3" -->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.heaboy.包名.base.dao" targetProject="項目名">
      <property name="enableSubPackages" value="false" />
    </javaClientGenerator>

    <!--對應資料庫表 mysql可以加入主鍵自增 字段命名 忽略某字段等 -->
    <table tableName="表名" domainObjectName="生成的實體名" enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"
      delimitIdentifiers="true">
      <property name="useActualColumnNames" value="true" />
    </table>

    <table tableName="表名2" domainObjectName="生成的實體名2" enableCountByExample="false"
      enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
      <property name="useActualColumnNames" value="true" />
    </table>
  </context>
</generatorConfiguration>
           

繼續閱讀