广告
返回顶部
首页 > 资讯 > 后端开发 > Python >mybatis-generator生成文件覆盖问题的解决
  • 176
分享到

mybatis-generator生成文件覆盖问题的解决

2024-04-02 19:04:59 176人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录mybatis-generator生成文件覆盖解决方案mybatis-generator避免覆盖自定义的sql方法mybatis-generator生成文件覆盖 在idea中使用

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 不会覆盖自定义的方法

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

--结束END--

本文标题: mybatis-generator生成文件覆盖问题的解决

本文链接: https://www.lsjlt.com/news/138503.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作