MyBatis generator配置 overwrite 文件覆盖失效

工具: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>

如果有更好的解决方法,欢迎大佬们留言。

原文地址:https://www.cnblogs.com/lihuajie/p/10599246.html

时间: 2024-08-04 14:27:31

MyBatis generator配置 overwrite 文件覆盖失效的相关文章

mybatis generator配置生成代码的问题

接触第二种orm两天下来,一脸懵逼.mybatis是大多数公司所推崇的,相比于hibernate性能较为好的,操作更为方便的轻量级工具,所以小富就搞起这个orm.好吧,都说mybatis有个配置可以自动生成相应的mapper,bean,dao文件.所以要先到myeclipse中配置一下generator的配置: 1.generator配置: 下载插件地址,根据目录找到这两个文件,放到myeclpse安装目录下 ------> 重启myeclipse后,输入mybatis就可以找到要生成的gene

Mybatis generator 配置报错

这个原因是:generator.xml文件中数据库连接配置错误所致! 对于oracle来说: 正确的配置是: <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@//192.168.x.x:port/Service_name(实例名.全局数据库名)" userId="xxx" password="

IDEA中Mybatis传统配置映射文件的时候遇到org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): mapper.UserMapper.getUserById错误时

我不知道是IDEA机制的问题还是咋回事   不会自动加载到这个文件里来  没搞太明白 原文地址:https://www.cnblogs.com/xkuankuan/p/9866435.html

Maven插件方式使用Mybatis Generator

Mybatis Generator Mybatis Generator简称MBG,可以根据数据库自动生成实体类.单表查询接口及其映射xml文件(也可以选择以注解方式生成). 下面介绍一下以maven插件方式使用MBG. 首先在pom中添加依赖: <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-cor

实习小结(四)--- MyBatis Generator使用

第一次听闻MyBatis Generator插件很是惊讶,已经有这么便捷方式的工具通过数据库表来自动生成实体类,映射文件,接口以及帮助类,而且可以通过自己写方法来增加中文注释,遂来学习一波.首先先建一个Maven的java项目 项目的目录结构 1.首先是pom.xml中的配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-ins

MyBatis映射实体类插件 MyBatis Generator

MyBatis Generator大大简化了MyBatis的数据库的代码编写,有了一个配置文件,就可以直接根据表映射成实体类.Dao类和xml映射. 资源地址: MyBatis项目地址:http://mybatis.github.io/ MyBatis中文使用文档:http://mybatis.github.io/mybatis-3/zh/index.html MyBatis Generator使用文档:http://mybatis.github.io/generator/index.html

springmvc+spring+mybatis+mysql配置过程

环境:eclipse 项目目录: jar包: web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http:/

mybatis 代码生成器配置

eclipse安装插件,new,新建一个Mybatis Generator Configuration File 文件内容: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http:

spring和mybatis整合配置

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p&