最近搞公司的項目,用的mybatis,寫好後測試,一直報錯:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):XXXXX
解決思路:
- mapper xml配置的localtion路徑不對,別名掃描路徑不對
- mapper xml中namespace
- mapper xml中方法名和mapper java是否匹配
如果你確定上邊都沒問題,那麼你可能是這個問題:
找到mapper下的target,發現編譯後的classes下xml沒有被編譯進去,所以一直沒有xml可以和方法對的上,需要在pom中加一個關閉xml 的filter過濾依賴。
<build>
<!-- 解決xml等文件不會被編譯問題-->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
上邊是代碼,放在你的mapper(我的父子項目,如果你是單體應用,直接放項目中pom即可)的pom.xml中,然後mvn clean ,重新編譯運行即可。
如果您覺得本篇文章不錯的話,感謝點贊,評論。