第一步 porm 文件引入插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis.generator.version}</version>
<configuration>
<verbose>true</verbose>
<!-- <overwrite>true</overwrite> -->
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version> </dependency> -->
</dependencies>
</plugin>
第二步:根目錄下導(dǎo)入兩個配置文件
(1)generatorConfig.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>
<!--執(zhí)行g(shù)enerator插件生成文件的命令: call mvn mybatis-generator:generate -e -->
<!-- 引入配置文件 -->
<properties resource="mybatisGeneratorinit.properties" />
<!--classPathEntry:數(shù)據(jù)庫的JDBC驅(qū)動,換成你自己的驅(qū)動位置 可選 -->
<!--<classPathEntry location="D:\generator_mybatis\mysql-connector-java-5.1.24-bin.jar"
/> -->
<!-- 一個數(shù)據(jù)庫一個context -->
<!--defaultModelType="flat" 大數(shù)據(jù)字段丈钙,不分表 -->
<context id="MysqlTables" targetRuntime="MyBatis3"
defaultModelType="flat">
<!-- 自動識別數(shù)據(jù)庫關(guān)鍵字甲雅,默認false螟够,如果設(shè)置為true山宾,根據(jù)SqlReservedWords中定義的關(guān)鍵字列表俗或; 一般保留默認值,遇到數(shù)據(jù)庫關(guān)鍵字(Java關(guān)鍵字)然痊,使用columnOverride覆蓋 -->
<property name="autoDelimitKeywords" value="true" />
<!-- 生成的Java文件的編碼 -->
<property name="javaFileEncoding" value="utf-8" />
<!-- beginningDelimiter和endingDelimiter:指明數(shù)據(jù)庫的用于標記數(shù)據(jù)庫對象名的符號哗伯,比如ORACLE就是雙引號,MYSQL默認是`反引號涣易; -->
<property name="beginningDelimiter" value="`" />
<property name="endingDelimiter" value="`" />
<!-- 格式化java代碼 -->
<property name="javaFormatter"
value="org.mybatis.generator.api.dom.DefaultJavaFormatter" />
<!-- 格式化XML代碼 -->
<property name="xmlFormatter"
value="org.mybatis.generator.api.dom.DefaultXmlFormatter" />
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<!-- 注釋 -->
<commentGenerator>
<property name="suppressAllComments" value="true" /><!-- 是否取消注釋 -->
<property name="suppressDate" value="true" /> <!-- 是否生成注釋代時間戳 -->
</commentGenerator>
<!-- jdbc連接 -->
<jdbcConnection driverClass="${jdbc_driver}"
connectionURL="${jdbc_url}" userId="${jdbc_user}" password="${jdbc_password}" />
<!-- 類型轉(zhuǎn)換 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal人乓, false可自動轉(zhuǎn)化以下類型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成實體類地址 -->
<javaModelGenerator targetPackage="com.fioc.ect.fproject.entity"
targetProject="${project}">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成mapxml文件 -->
<sqlMapGenerator targetPackage="mappers"
targetProject="${resources}">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成mapxml對應(yīng)client,也就是接口dao -->
<javaClientGenerator targetPackage="com.fioc.ect.fproject.dao"
targetProject="${project}" type="XMLMAPPER">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- ta_custinfo 投資人基本信息-->
<!-- <table tableName="ta_custinfo" enableInsert="true"
enableUpdateByPrimaryKey="true" enableDeleteByExample="true"
enableDeleteByPrimaryKey="true" enableUpdateByExample="true"
enableCountByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="true" />
</table> -->
<table tableName="bside_product" enableInsert="true"
enableUpdateByPrimaryKey="true" enableDeleteByExample="true"
enableDeleteByPrimaryKey="true" enableUpdateByExample="true"
enableCountByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="true" />
</table>
</context>
</generatorConfiguration>
(2)mybatisGeneratorinit.properties:
#Mybatis Generator configuration
#dao and entity location
project=src/main/java
#mapper location
resources=src/main/resources
jdbc_driver=com.mysql.jdbc.Driver
jdbc_url=jdbc:mysql://localhost:3306/ta
jdbc_user=buyside
jdbc_password=buyside
第三步
執(zhí)行命令:mybatis-generator:generate