1.编写generatorConfig.xml(本文中为MBG.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>
<properties resource="druid.properties"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 阻止自动生成的注释 true:是 : false:否 -->
<commentGenerator>
<property name="suppressDate" value="true" />
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库连接-->
<jdbcConnection driverClass="${driverClassName}"
connectionURL="${url}"
userId="${username}"
password="${password}">
</jdbcConnection>
<!--是否需要强转成BigDecimal类型-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 实体类生成器 -->
<javaModelGenerator targetPackage="priv.wjl.generator.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- mapper.xml生成器 -->
<sqlMapGenerator targetPackage="priv.wjl.generator.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- mapper.java生成器 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="priv.wjl.generator.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 匹配数据库表 -->
<table tableName="manager"></table>
<table tableName="student"></table>
<table tableName="score"></table>
<table tableName="lesson"></table>
<table tableName="sets"></table>
<table tableName="question"></table>
</context>
</generatorConfiguration>
2.在pom.xml中添加插件
<!--mybatis逆向生成-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<configurationFile>src/main/resources/MBG.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
</dependencies>
</plugin>
3.依次点击菜单Run,Edit Configurations,'+',maven。
修改command line为mybatis-generator:generate -e ,点ok。如图: