mybatis-generator生成文件覆蓋問(wèn)題的解決
mybatis-generator生成文件覆蓋
在Idea中使用Mybatis-generator plugin時(shí)遇到的問(wèn)題,我的mybatis配置到的DB的服務(wù)中,每次部署微服務(wù)時(shí)需要install db這個(gè)微服務(wù),將其打成jar包,供其他服務(wù)引用。
可是發(fā)現(xiàn),我每次install或者package時(shí)候,mybatis-generator都會(huì)隨編譯自動(dòng)運(yùn)行,導(dǎo)致工程中的的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時(shí)候運(yùn)行該插件,導(dǎo)致本地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方法
編寫(xiě)PersonExtMapper.java 接口文件 編寫(xiě)自定義方法
編寫(xiě)PersonExtMapper.xml 映射文件 配置映射
PersonExtMapper.xml 和PersontMapper.xml(Mybatis生成器生成)的區(qū)別
指向各自的Maper接口文件
但相同
當(dāng)數(shù)據(jù)庫(kù)字段發(fā)生改變 執(zhí)行指令mvn -Dmybatis.generator.overwrite=true mybatis-generator:generate 不會(huì)覆蓋自定義的方法
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
mybatis-plus開(kāi)啟sql日志打印的三種方法
本文主要介紹了mybatis-plus開(kāi)啟sql日志打印的三種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05
去掉IntelliJ IDEA 中 mybatis 對(duì)應(yīng)的 xml 文件警告的教程圖解
本文通過(guò)圖文并茂的形式給大家介紹了去掉IntelliJ IDEA 中 mybatis 對(duì)應(yīng)的 xml 文件警告的教程,需要的朋友可以參考下2018-06-06
SpringMVC使用MultipartFile 實(shí)現(xiàn)異步上傳方法介紹
這篇文章主要介紹了SpringMVC使用MultipartFile 實(shí)現(xiàn)異步上傳方法介紹,涉及pom依賴(lài)的添加,配置文件的修改等具體操作代碼,需要的朋友可以了解下。2017-09-09
Hibernate+JDBC實(shí)現(xiàn)批量插入、更新及刪除的方法詳解
這篇文章主要介紹了Hibernate+JDBC實(shí)現(xiàn)批量插入、更新及刪除的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Hibernate與JDBC針對(duì)數(shù)據(jù)庫(kù)的批量操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-11-11
Mybatis-Spring連接mysql 8.0配置步驟出錯(cuò)的解決方法
這篇文章主要為大家詳細(xì)介紹了Mybatis-Spring連接mysql 8.0配置步驟出錯(cuò)的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06
注意Java中?new?BigDecimal(double?val)?的使用
這篇文章主要介紹了注意Java中?new?BigDecimal(double?val)?的使用,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07
Spring-AOP-ProceedingJoinPoint的使用詳解
這篇文章主要介紹了Spring-AOP-ProceedingJoinPoint的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-03-03

