MyBatis Generator的简单使用
目的是快速进入项目使用状态,具体的参数配置可以后期修改(如数据库连接、配置文件目录位置等)
1、POM中加入插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector.version}</version>
</dependency>
<dependency>
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.2.10</version>
</dependency>
</dependencies>
</plugin>
2、在resources目录加创建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>
<context id="mysql" defaultModelType="flat" targetRuntime="MyBatis3">
<property name="autoDelimitKeywords" value="false"/>
<property name="javaFileEncoding" value="UTF-8"/>
<property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<plugin type="com.itfsw.mybatis.generator.plugins.LimitPlugin"/>
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/>
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin">
<!-- 修改Example类生成到目标包下 -->
<property name="targetPackage" value="com.test.pay.finance.example"/>
</plugin>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://xxxx.com:3306/test"
userId="test"
password="123456">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="true" />
</javaTypeResolver>
<javaModelGenerator targetPackage="com.test.pay.finance.entity" targetProject="src/main/java">
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.test.pay.finance.mapper" targetProject="src/main/resources">
</sqlMapGenerator>
<javaClientGenerator type="MIXEDMAPPER" targetPackage="com.test.pay.finance.mapper" targetProject="src/main/java" />
<table schema="finance" tableName="arrival_reminder" >
<property name="useActualColumnNames" value="true"/>
<generatedKey column="id" sqlStatement="MySql" identity="true" />
<!-- 生成的实体类等去掉表名的前缀。注意,与正则要写驼峰转化后的。或者在table标签添加domainObjectName属性直接指定 -->
<domainObjectRenamingRule searchString="^T" replaceString=""/>
</table>
</context>
</generatorConfiguration>