1. 程式人生 > >MyBatis generator配置 overwrite 文件覆蓋失效

MyBatis generator配置 overwrite 文件覆蓋失效

Coding mys bye ORC conf group 詳解 oca schema

工具:IDEA、jdk1.8、mysql

底部有解決方法!

pom.xml配置

<plugins>
      <!--Mybatis自動代碼插入-->
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.7</version>
        <configuration>
          <!--允許移動生成的文件-->
          <verbose>true</verbose>
          <!--允許覆蓋生成的文件-->
          <overwrite>true</overwrite>
        </configuration>
      </plugin>
    </plugins>

generator.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">
<!--generator配置詳解:https://blog.csdn.net/zhaoyachao123/article/details/78961737-->

<generatorConfiguration>
    <!--導入屬性配置-->
    <properties resource="generator.properties"/>

    <classPathEntry location="${driverLocalhost}"/>
    <context id="Mysql" defaultModelType="flat">
        <!--覆蓋生成XML文件 generator1.3.7版本-->
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"></plugin>
        <!--註釋-->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/><!--是否取消註釋-->
            <property name="suppressDate" value="true"/><!--是否生成註釋代時間戳-->
        </commentGenerator>


        <jdbcConnection driverClass="${driver}"
                        connectionURL="${url}"
                        userId="${username}"
                        password="${password}"/>
        <!--類型轉換-->
        <javaTypeResolver>
            <!--是否使用bigDecimal,false可自動轉化以下類型(Long,Integer,Short,etc.)-->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <javaModelGenerator targetPackage="${modelPackage}" targetProject="${modelProject}" />
        <sqlMapGenerator targetPackage="${sqlPackage}" targetProject="${sqlProject}" />
        <javaClientGenerator targetPackage="${mapperPackage}" targetProject="${mapperProject}" type="XMLMAPPER"/>

        <!--如果需要通配所有表 tableName 直接用sql的通配符 %即可-->
        <!--enableCountByExample(默認true):MyBatis3Simple為false,指定是否生成動態查詢總條數語句(用於分頁的總條數查詢);-->
        <!--enableUpdateByExample(默認true):MyBatis3Simple為false,指定是否生成動態修改語句(只修改對象中不為空的屬性);-->
        <!--enableDeleteByExample(默認true):MyBatis3Simple為false,指定是否生成動態刪除語句;-->
        <!--enableSelectByExample(默認true):MyBatis3Simple為false,指定是否生成動態查詢語句;-->
        <table schema="" tableName="%" enableCountByExample="false"
                enableUpdateByExample="false" enableDeleteByExample="false"
                enableSelectByExample="false" selectByExampleQueryId="false"/>

    </context>

</generatorConfiguration>
generator.properties
driverLocalhost = E:/Maven_Repo/mysql/mysql-connector-java/5.1.45/mysql-connector-java-5.1.45.jar

driver = com.mysql.jdbc.Driver url = jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8 username=root password=****** #entity 包名和 java目錄 modelPackage=com.stemCell.entity modelProject=src/main/java #mapper包名 和resources目錄 sqlPackage=mapper sqlProject=src/main/resources #dao包名和 java目錄 mapperPackage=com.stemCell.dao mapperProject=src/main/java #測試時使用,生成message表 table=message

解決方案:

①:mybatis-generator-maven-plugin版本改為1.3.7(個人試用過1.3.2和1.3.5均無法解決這問題)
②:在generatorConfig.xml中的<context>下添加:
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"></plugin>

如果有更好的解決方法,歡迎大佬們留言。

MyBatis generator配置 overwrite 文件覆蓋失效