mybatis mysql count(*) 返回結果為null的解決


具體錯誤信息:

org.apache.ibatis.binding.BindingException: Mapper method 'com.xx.xx.xx.xx.xx.getCount attempted to return null from a method with a primitive return type (int). 

 

定義的Integer,怎么會返回null呢?mysql版本問題?

不是這樣的,仔細檢查sql語句,加了group by ,那么count(*)在檢索后如果沒有任何數據,那就會返回null。

解決:

 

  1.  
    SELECT COUNT(*) FROM (
  2.  
    <! -- 原來的sql -->
  3.  
    ) t


再試下,ok


免責聲明!

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



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