mybatis-generator有三种用法:命令行、eclipse插件、maven插件。
maven插件
一、在pom.xml中添加plugin<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
二、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:数据库的JDBC驱动,换成你自己的驱动位置 -->
<classPathEntry location="E:\java\mybatis-generator-core-1.3.2\lib\mysql-connector-java-5.1.25-bin.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 去除自动生成的注释 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接配置 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/eseip" userId="victool" password="victool">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- targetProject:自动生成代码的位置 -->
<javaModelGenerator targetPackage="test.domain" targetProject="E:\java\mybatis-generator-core-1.3.2\lib\src">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- targetProject:自动生成代码的位置 -->
<sqlMapGenerator targetPackage="test.mapping" targetProject="E:\java\mybatis-generator-core-1.3.2\lib\src">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- targetProject:自动生成代码的位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="test.IDao" targetProject="E:\java\mybatis-generator-core-1.3.2\lib\src">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
<table tableName="ac_account" domainObjectName="AcAccountDef" />
<table tableName="ac_account_area" domainObjectName="AcAccountAreaDef" />
<table tableName="ac_account" domainObjectName="AcAccountDef" />
<table tableName="ac_account_area" domainObjectName="AcAccountAreaDef" />
<!-- <table tableName="activity_info" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->
</context>
</generatorConfiguration>