使用mybatis報錯:Mapper method 'com.xin.dao.BlogMapper.addBlog attempted to return null from a method with a primitive return type (int).


錯誤原因

  • 分析

本次報錯的原因在於sql語句未查詢到數據,返回為null。而我們定義的dao層方法是返回為int,就會出現如下這樣的提示:
return null from a method with a primitive return type (int).(試圖從具有原始返回類型(int)的方法返回null)
Ingeter是int的包裝類,int的初值為0,Ingeter的初值為null

  • 解決方式

將dao層的返回類型改為Integer即可。

 

改為:

 


免責聲明!

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



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