最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MyBatis-Plus找不到Mapper.xml文件的幾種解決方法

 更新時(shí)間:2022年06月30日 09:26:26   作者:Stone?Lio  
mybatis-plus今天遇到一個(gè)問(wèn)題,就是mybatis 沒(méi)有讀取到mapper.xml 文件,所以下面這篇文章主要給大家介紹了關(guān)于MyBatis-Plus找不到Mapper.xml文件的幾種解決方法,需要的朋友可以參考下

在整合SpringBoot和Mybatis-plus時(shí),想寫(xiě)自定義的sql,所以創(chuàng)建了Mapper.xml文件,但是啟動(dòng)后卻老是報(bào)錯(cuò):

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

很明顯,是Mapper.xml未被掃描到。

此類(lèi)問(wèn)題的解決方式實(shí)際上都是配置上有問(wèn)題,以下列出了一些解決方式。

方式1:Mapper的命名空間和Dao層的接口。

Mapper.xml文件中,<mapper namespace="這里填寫(xiě)映射的Mapper.java完整路徑,如:com.test.Mapper">

方式2:如果Mapper.xml文件是放到j(luò)ava目錄下,那么在項(xiàng)目的pom.xml文件中需要添加:

<build>
? ? ? ? <resources>
? ? ? ? ? ? <resource>
? ? ? ? ? ? ? ? <directory>src/main/java</directory>
? ? ? ? ? ? ? ? <includes>
? ? ? ? ? ? ? ? ? ? <include>**/*.xml</include>
? ? ? ? ? ? ? ? </includes>
? ? ? ? ? ? </resource>
? ? ? ? </resources>
</build>

方式3:注意在.yml配置文件中不要弄混淆Mybatis和Mybatis-plus的配置

比如項(xiàng)目pom.xml中引用的是Mybatis-plus的starter,其中已經(jīng)包含了Mybatis了,配置文件中最好統(tǒng)一寫(xiě)成Mybatis-plus的配置:

mybatis:
? ? mapper-locations: classpath:com/*/mapper/xml/*.xml

改成

mybatis-plus:
? ? mapper-locations: classpath:com/*/mapper/xml/*.xml

方式4:如果是多子模塊的項(xiàng)目,Mapper.xml文件是在子模塊項(xiàng)目中,那么記得在classpath后面加*,代表掃描子項(xiàng)目的Mapper.xml文件

mybatis-plus:

    mapper-locations: classpath*:com/*/mapper/xml/*.xml

方式5:我最近放的一個(gè)小錯(cuò)誤,就是我的Mapper.xml文件是放在不同層次不同包下的,我配置了很多個(gè)掃描位置:

mybatis-plus:

    mapper-locations: classpath*:com/*/mapper/xml/*.xml,com/test/*/mapper/xml/*.xml,/xml/*.xml

配置好發(fā)現(xiàn)依然報(bào)未掃描到Mapper.xml文件,后來(lái)發(fā)現(xiàn),我的Mapper.xml文件是放到子模塊中的"com/test/*/mapper/xml"目錄下,配置應(yīng)該要繼續(xù)帶上classpath*:

上面的配置改成:

mybatis-plus:

    mapper-locations: classpath*:com/*/mapper/xml/*.xml,classpath*:com/test/*/mapper/xml/*.xml,/xml/*.xml

因?yàn)槁窂角懊娌粠н@個(gè)"classpath*"它默認(rèn)是使用的"classpath",導(dǎo)致掃描不到子模塊項(xiàng)目的Mapper.xml文件。

總結(jié)

到此這篇關(guān)于MyBatis-Plus找不到Mapper.xml文件的幾種解決方法的文章就介紹到這了,更多相關(guān)MyBatis-Plus找不到Mapper.xml文件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

甘孜县| 德阳市| 南溪县| 东兰县| 江津市| 舞阳县| 长阳| 新化县| 离岛区| 永安市| 辉县市| 贵阳市| 荥经县| 嘉善县| 大安市| 伊吾县| 通许县| 行唐县| 青海省| 乌鲁木齐市| 水富县| 灵丘县| 谷城县| 陇川县| 马山县| 长葛市| 罗定市| 上饶县| 宜君县| 万载县| 蚌埠市| 南安市| 姜堰市| 绥江县| 灵璧县| 沧源| 米易县| 宁晋县| 长治市| 文登市| 安乡县|