參考:
http://www.reibang.com/p/fcd66129f6e6
用maven plugin的方式生成代碼
- pom.xml 里面配置 plugin的屬性
- 在resources 下面創(chuàng)建 generatorConfig.xml 乘粒、mysql.properties
- generatorConfig.xml的配置注意 context.targetRuntime 屬性,MyBatis3時(shí)會(huì)是全量的實(shí)體類修陡,MyBatis3Simple 只會(huì)生成簡(jiǎn)單的 sql
- 在 plugins 里面 mvn run generate 生成最終的代碼
<properties>
<mbg.version>1.3.7</mbg.version>
<!-- Java接口和實(shí)體類生成路徑
targetMapperPackage是生成的接口包名
targetModelPackage是生成的實(shí)體類包名
-->
<targetJavaProject>${basedir}/src/main/java</targetJavaProject>
<targetMapperPackage>com.hyzx.qbasic.domain.dao</targetMapperPackage>
<targetModelPackage>com.hyzx.qbasic.common.model.po</targetModelPackage>
<!-- XML生成路徑 -->
<targetResourcesProject>${basedir}/src/main/java</targetResourcesProject>
<targetXMLPackage>mapper</targetXMLPackage>
</properties>
<plugin>
<!-- MBG插件 -->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mbg.version}</version>
<configuration>
<!-- MBG配置文件路徑 -->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
</dependencies>
</plugin>
jdbc.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://127.0.0.1/ss_openapi_gateway_dev?useUnicode=true&characterEncoding=utf-8&useSSL=false
db.username=root
db.password=123456
<context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">