mybatis錯誤之org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)


玩了MyBatis差不多有兩年了,中間也玩過MyBatis-Plus,這個MyBatis-Plus其實與MyBatis的區別並不大。今天寫博客業務代碼的時候,犯一個初學者犯過的錯誤。

錯誤信息如下:
org.apache.ibatis.binding.BindingException: Invalid bound statement
(not found)

通常原因是因為Mapper interface和xml文件的定義對不上,通常需要檢查包名、namespace、函數名等。

出現這個錯誤的原因是我太過相信自我了,覺得自覺沒有錯,於是手打,結果就是一個單詞寫錯了。

看代碼示例:

xml:

<select id="resentPosts" resultMap="BaseResultMap">
     SELECT post_title FROM `wp_posts` WHERE post_status = 'publish' ORDER BY post_modified DESC LIMIT 0,5 
 </select>

dao(interface):

//近期文章
public List<Posts> recentPosts();

大家很容易會看出select標簽中的id與dao中的接口函數名不對應。這就是問題的根源,改成一樣的,如下(即可解決問題)

<select id="recentPosts" resultMap="BaseResultMap">
      SELECT post_title FROM `wp_posts` WHERE post_status = 'publish' ORDER BY post_modified DESC LIMIT 0,5 
  </select>

最后說一句,遇到問題不要慌,找到問題關鍵信息,復制到百度上/谷歌或者stackoverflow即可找到答案。

太陽底下沒有新鮮事兒,你遇到過的,說不定別人也遇到過。

參考鏈接:https://www.cnblogs.com/lfm601508022/p/InvalidBoundStatement.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM