解決mybatis報錯org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
如果出現報錯
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.nriat.core.system.dao.UserMapper.findByUserName] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxx(com.nriat.core.system.dao.UserMapper.findByUserName這個是我自己的mapper方法,各人可能不同)

1.首先檢查自己的mapper中是否有這個方法

2.檢查對應的mapper中是否配置了對應的方法

3.檢查xml的命名空間是否是有對應到mapper介面

4.如果以上三點檢查了都沒有問題,那么可以肯定,代碼應該是沒有問題的,那問題出現在哪呢?
檢查一下target中的classes檔案

這樣一來,問題就找到了,那我們應該怎么解決呢?
解決辦法:
在pom.xml中添加如下buid,目的就是讓mapper檔案在編譯后也加入到classes檔案中,
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<!-- 打包時排除JRebel插件生成的組態檔 -->
<excludes>
<exclude>**/rebel.xml</exclude>
</excludes>
</resource>
<!-- 打包所有resources下的檔案 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
</build>
最終結果

問題解決!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/253468.html
標籤:java
上一篇:Java學習筆記(9):圖形介面
