Mapper method XXX attempted to return null from a method with a primitive return type (int).

这个异常信息简单来说就是mybatis查询结果为null,但是返回的又int这种基本数据类型的时候报的错
原因就是这些基本类型无法赋值为null

解决

既然知道是基本类型的原因,我们可以把基本类型修改为对应的包装类型。如:int->Integer
如果你sql中有用到聚合函数时,如:sum这些,在oracle中可以稍微处理一下,如:nvl(sum(num),0)

异常信息定位
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 
   if (method.getDeclaringClass() == Object.class) {
       return method.invoke(this, args); 
    }
    final Class declaringInterface = findDeclaringInterface(proxy, method); 
    final MapperMethod mapperMethod = new MapperMethod(declaringInterface,method,sqlSession); 
    final Object result = mapperMethod.execute(args);
    if (result == null && method.getReturnType().isPrimitive() && !method.getReturnType().equals(Void.TYPE){
          throw new BindingException("Mapper method '" + method.getName()
          + "' (" + method.getDeclaringClass() + ") attempted to return null from a method with a primitive return type (" + method.getReturnType() + ")."); 
      } 
     return result;
 }

你可能感兴趣的:(Mapper method XXX attempted to return null from a method with a primitive return type (int).)