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

原文地址:https://www.cnblogs.com/yelanggu/p/14420342.html