在pom.xml 新加
<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>
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 location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar" /> <context id="context1" targetRuntime="MyBatis3"> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test" userId="root" password="huhanbo"> </jdbcConnection> <!-- <javaTypeResolver> --> <!-- <property name="forceBigDecimals" value="false" /> --> <!-- </javaTypeResolver> --> <!-- 实体定义地址 --> <javaModelGenerator targetPackage="com.me.mybatis.entity" targetProject="D:\Busys_Project\project\test\test\src\main\java" /> <!-- sql的配置文件定义 --> <sqlMapGenerator targetPackage="mybatisMapper" targetProject="D:\Busys_Project\project\test\test\src\main\resources" /> <!-- DAO定义 XMLMAPPER是xml的配置方式,还有ANNOTabelMapper的是注解方式 --> <javaClientGenerator targetPackage="com.me.mybatis.persistence" targetProject="D:\Busys_Project\project\test\test\src\main\java" type="XMLMAPPER" /> <table tableName="company" domainObjectName="Company" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
配置好后,点击如下,就会在上面配置的对应目录生成
参考博客:
http://www.cnblogs.com/yjmyzz/p/mybatis-generator-tutorial.html
原文:http://www.cnblogs.com/huhanbo/p/7537766.html