mybatis-generator生成文件覆盖

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

mybatis-generator生成文件覆盖

小明同鞋   2022-05-23 我要评论

mybatis-generator生成文件覆盖

在Idea中使用Mybatis-generator plugin时遇到的问题,我的mybatis配置到的DB的服务中,每次部署微服务时需要install db这个微服务,将其打成jar包,供其他服务引用。

可是发现,我每次install或者package时候,mybatis-generator都会随编译自动运行,导致工程中的的mapper和dao都被冲掉。

解决方案

<configuration>
    <!--配置文件的位置-->
    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
    <verbose>true</verbose>
    <overwrite>true</overwrite>
</configuration>
<executions>
    <execution>
        <id>Generate MyBatis Artifacts</id>
        <!-- 该配置可避免maven install或者package时候运行该插件,导致本地mapper重新生成 -->
        <phase>deploy</phase>
        <goals>
            <goal>generate</goal>
        </goals>
    </execution>
</executions>
<dependencies>
    <dependency>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-core</artifactId>
        <version>1.3.2</version>
    </dependency>
</dependencies>

官方文档中有如下描述:

The MBG plugin is bound to the generate-sources phase of a Maven build, so it will execute before the compile step. Also note that MBG generates both Java source files and XML resources. The MBG goal will bind both generated Java files and XML resources to the build and they will both be included in any JAR generated by the build.

mybatis-generator避免覆盖自定义的sql方法

编写PersonExtMapper.java 接口文件 编写自定义方法

编写PersonExtMapper.xml 映射文件 配置映射

PersonExtMapper.xml 和PersontMapper.xml(Mybatis生成器生成)的区别

指向各自的Maper接口文件

但相同

当数据库字段发生改变 执行指令mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate 不会覆盖自定义的方法

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们