1.在项目的配置文件中放入配置文件mybatis-generator-config.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> <!-- !!!! Driver Class Path !!!! -->
<classPathEntry location="/Users/dongjunjie/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar"/> <context id="context" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
<commentGenerator>
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator> <!-- !!!! Database Configurations !!!! -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://****/exchange?characterEncoding=utf-8"
userId="exchange" password="****"/> <javaTypeResolver>
<property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- !!!! Model Configurations !!!! -->
<javaModelGenerator targetPackage="com.cmcm.finance.wallet.sync.entity" targetProject="/Users/dongjunjie/IdeaProjects/wallet-sync/src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!-- !!!! Mapper XML Configurations !!!! -->
<sqlMapGenerator targetPackage="sqlmapper" targetProject="/Users/dongjunjie/IdeaProjects/wallet-sync/src/main/java/com/*/finance/wallet/sync/dao">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator> <!-- !!!! Mapper Interface Configurations !!!! -->
<javaClientGenerator targetPackage="com.*.finance.wallet.sync.dao" targetProject="/Users/dongjunjie/IdeaProjects/wallet-sync/src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator> <!-- !!!! Table Configurations !!!! -->
<table tableName="distribute_coin_detail" domainObjectName="DistributeCoinDetail" enableCountByExample="true" enableDeleteByExample="true" enableSelectByExample="true"
enableUpdateByExample="true"/> </context>
</generatorConfiguration>
2. 添加maven 任务
Edit-Configurations ->name 、work directory、Command line (mybatis-generator:generate -e )
3. pom 文件中添加 build -plugin
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/dev/mybatis-generator-config.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</plugin>
4. 运行maven的自动生成插件
run-config 》 mybatis-gen -》右键 run
pom中添加Plugins 也可以在idea的maven project中 的Plugins中找到mybatis-generater 右键运行即可