maven新增mybatis-generator
maven pom.xml:
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>false</verbose>
<overwrite>false</overwrite>
</configuration>
</plugin>
</plugins>
</build>
建立 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>
<classPathEntry
location="E:\myeclipse\test_aop\src\main\resources\mysql-connector-java-5.1.38.jar" />
<context id="sqlserverTables" targetRuntime="MyBatis3">
<!-- 生成的pojo,將implements Serializable -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<commentGenerator>
<!-- 是否去除自動生成的註釋 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 資料庫連結URL、使用者名稱、密碼 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?characterEncoding=utf8" userId="root" password="root">
</jdbcConnection>
<!-- 預設false,把JDBC DECIMAL 和 NUMERIC 型別解析為 Integer true,把JDBC DECIMAL
和 NUMERIC 型別解析為java.math.BigDecimal -->
<!-- 生成model模型,對應的包路徑,以及檔案存放路徑(targetProject),targetProject可以指定具體的路徑,如./src/main/java,
也可以使用“MAVEN”來自動生成,這樣生成的程式碼會在target/generatord-source目錄下 -->
<!--<javaModelGenerator targetPackage="com.joey.mybaties.test.pojo" targetProject="MAVEN"> -->
<javaModelGenerator targetPackage="com.csdn.ingo.entity"
targetProject="./src/main/java">
<property name="test_aop" value="true" />
<!-- 從資料庫返回的值被清理前後的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--對應的mapper.xml檔案 -->
<sqlMapGenerator targetPackage="mappers"
targetProject="./src/main/java">
<property name="test_aop" value="true" />
</sqlMapGenerator>
<!-- 對應的Mapper介面類檔案 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.csdn.ingo.dao" targetProject="./src/main/java">
<property name="test_aop" value="true" />
</javaClientGenerator>
<!-- 列出要生成程式碼的所有表,這裡配置的是不生成Example檔案 -->
<table tableName="gt_hotel"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
右鍵專案->run as ->configurations...
成功:
案例: