mybatis-generator生成文件覆盖问题的解决
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 不会覆盖自定义的方法
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
去掉IntelliJ IDEA 中 mybatis 对应的 xml 文件警告的教程图解
本文通过图文并茂的形式给大家介绍了去掉IntelliJ IDEA 中 mybatis 对应的 xml 文件警告的教程,需要的朋友可以参考下2018-06-06
SpringMVC使用MultipartFile 实现异步上传方法介绍
这篇文章主要介绍了SpringMVC使用MultipartFile 实现异步上传方法介绍,涉及pom依赖的添加,配置文件的修改等具体操作代码,需要的朋友可以了解下。2017-09-09
Hibernate+JDBC实现批量插入、更新及删除的方法详解
这篇文章主要介绍了Hibernate+JDBC实现批量插入、更新及删除的方法,结合实例形式较为详细的分析了Hibernate与JDBC针对数据库的批量操作相关实现技巧,需要的朋友可以参考下2017-11-11
Mybatis-Spring连接mysql 8.0配置步骤出错的解决方法
这篇文章主要为大家详细介绍了Mybatis-Spring连接mysql 8.0配置步骤出错的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2019-06-06
注意Java中 new BigDecimal(double val) 的使用
这篇文章主要介绍了注意Java中 new BigDecimal(double val) 的使用,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的朋友可以参考一下2022-07-07
Spring-AOP-ProceedingJoinPoint的使用详解
这篇文章主要介绍了Spring-AOP-ProceedingJoinPoint的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2025-03-03


最新评论