這個(gè)異常信息簡(jiǎn)單來(lái)說(shuō)就是mybatis查詢結(jié)果為null,但是返回的又int這種基本數(shù)據(jù)類型的時(shí)候報(bào)的錯(cuò)
原因就是這些基本類型無(wú)法賦值為null
解決
既然知道是基本類型的原因,我們可以把基本類型修改為對(duì)應(yīng)的包裝類型。如:int->Integer
如果你sql中有用到聚合函數(shù)時(shí)嫌吠,如: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;
}