使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件(转)
https://www.cnblogs.com/smileberry/p/4145872.html
===================================================================
一种改进的方式:把数据和配置分离开来,更优雅
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> </plugin>
<?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="generator.properties" /> <classPathEntry location="${maven.repo}mysqlmysql-connector-java${jdbc.driver.version}mysql-connector-java-${jdbc.driver.version}.jar" /> <context id="MySQL" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="beginningDelimiter" value="`" /> <property name="endingDelimiter" value="`" /> <commentGenerator> <property name="suppressAllComments" value="true" /> <property name="suppressDate" value="true" /> </commentGenerator> <jdbcConnection driverClass="${jdbc.driver.class}" connectionURL="${jdbc.connection.url}" userId="${jdbc.userId}" password="${jdbc.password}"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <javaModelGenerator targetPackage="${model.targetPackage}" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="${sqlmap.targetPackage}" targetProject="src/main/resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="${client.targetPackage}" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <table tableName="tb_zxx_demonstration_period" domainObjectName="DemonstrationPeriod" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
#maven.repo=D:\workshop\repo #maven.repo=C:\Users\yzy\.m2\repository maven.repo=C:\Users\Administrator\.m2\repository #jdbcu9A71u52A8u7C7Bu540D jdbc.driver.class=com.mysql.jdbc.Driver #jdbcu9A71u52A8u7248u672C jdbc.driver.version=5.1.26 jdbc.connection.url=jdbc:mysql://127.0.0.1:23306/test?useUnicode=true&characterEncoding=UTF-8 #jdbcu8FDEu63A5u7528u6237u540D jdbc.userId=root #jdbcu8FDEu63A5u5BC6u7801 jdbc.password=root #u9879u76EEu6E90u7801u8DEFu5F84 targetProject=src/main/resources #modelu5305u8DEFu5F84 model.targetPackage=com.baidu.qqhy.zxx.entity client.targetPackage=com.baidu.qqhy.zxx.mapper sqlmap.targetPackage=mapper