pom.xml
<groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <!--配置文件的位置--> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration>
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_tables" targetRuntime="MyBatis3"> <!-- 防止生成的代码中有很多注释,加入下面的配置控制 --> <commentGenerator> <property name="suppressAllComments" value="true" /> <property name="suppressDate" value="true" /> </commentGenerator> <!-- 数据库连接 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/数据库" userId="root" password="root"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 数据表对应的model层 --> <javaModelGenerator targetPackage="包地址" targetProject="src/main/java"> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> <property name="" value="" /> </javaModelGenerator> <!-- sql mapper 映射配置文件 --> <sqlMapGenerator targetPackage="
包地址
"
targetProject
="src/main/java"> <
property
name
="enableSubPackages"
value
="false" /> </
sqlMapGenerator>
<!-- mybatis3中的mapper接口 -->
<
javaClientGenerator
type
="XMLMAPPER"
targetPackage
="
包地址
"
targetProject
="src/main/java"> <
property
name
="enableSubPackages"
value
="false" /> </
javaClientGenerator>
<!-- 数据表进行生成操作 schema:相当于库名; tableName:表名; domainObjectName:对应的DO -->
<
table
schema
="工程名"
tableName
="表名"
domainObjectName
="实体类"
enableCountByExample
="true"
enableUpdateByExample
="true"
enableDeleteByExample
="true"
enableSelectByExample
="true"
selectByExampleQueryId
="true"> </
table>
</
context></
generatorConfiguration>
执行生成
mvn mybatis-generator:generate
生成Mybatis文件