mybatis-generator生成文件覆盖问题的解决
作者:小明同鞋 时间:2023-03-11 15:35:01
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 不会覆盖自定义的方法
来源:https://blog.csdn.net/sinat_30802291/article/details/82692299
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Spring框架注解扫描开启之配置细节
Android WebP 图片压缩与传输
![](https://img.aspxhome.com/file/2023/8/130328_0s.jpg)
AlertDialog点击按钮不消失的实现方法
@ConfigurationProperties加载外部配置方式
![](https://img.aspxhome.com/file/2023/5/59385_0s.png)
springboot配置https访问的方法
Java线程池并发执行多个任务方式
![](https://img.aspxhome.com/file/2023/4/80274_0s.jpg)
Intellij Idea修改代码方法参数自动提示快捷键的操作
![](https://img.aspxhome.com/file/2023/8/75748_0s.jpg)
面试官:java ThreadLocal真的会造成内存泄露吗
![](https://img.aspxhome.com/file/2023/7/79937_0s.png)
C#实现字符串与图片的Base64编码转换操作示例
Android显示富文本+夜间深色模式
![](https://img.aspxhome.com/file/2023/9/111709_0s.png)
Java实现的计时器【秒表】功能示例
![](https://img.aspxhome.com/file/2023/1/59051_0s.gif)
C#实现汉字转拼音或转拼音首字母的方法
SpringBoot如何使用自定义注解实现接口限流
![](https://img.aspxhome.com/file/2023/0/60110_0s.png)
Android编程之SharedPreferences文件存储操作实例分析
![](https://img.aspxhome.com/file/2023/3/138923_0s.png)
Android实现应用内置语言切换功能
![](https://img.aspxhome.com/file/2023/6/138526_0s.jpg)
详解Java的回调机制
![](https://img.aspxhome.com/file/2023/7/60657_0s.png)
IDEA:Git stash 暂存分支修改的实现代码
![](https://img.aspxhome.com/file/2023/3/78363_0s.jpg)
Android Build Variants 为项目设置变种版本的方法
![](https://img.aspxhome.com/file/2023/1/89541_0s.jpg)
Android开发之保存图片到相册的三种方法详解
Android仿知乎客户端关注和取消关注的按钮点击特效实现思路详解
![](https://img.aspxhome.com/file/2023/5/94975_0s.png)