attempted to return null from a method with a primitive return type (Double).


  1. <select id="getMaxHitEventId" parameterType="string" resultType="int">  
  2.     select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV}  
  3. </select>  

mybatis+mysql查詢出來會報如下錯誤:
attempted to return null from a method with a primitive return type (int).
我的返回值類型為int,但是查詢出來的結果有空值,所以會出現如上的異常,以下為解決辦法:

1.當查詢出來為空時,給賦值一個默認值:

  1. select IFNULL(max(app_hitEventID),0) from hits_tab_app where app_hitV=#{app_hitV}  

2.將返回值類型改為Integer,然后由業務代碼去進行判斷:

  1. <select id="getMaxHitEventId" parameterType="string" resultType="Integer">  
  2.     select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV}  
  3. </select>  

 


免責聲明!

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



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