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

异常背景
mybatis mapper.xml 中
resultType = int
select count(*)

count(*)查询结果为null,所以出现上述的异常

异常分析:
attempted to return null from a method with a primitive return type (int)

尝试为int赋值为null

异常解决:
1.select IFNULL(count(*),0) 空处理,默认为0

2.resultType = java.lang.Integer 在Service 中调用 mapper.java 接口时做空的判断

异常总结:
无论 resultType 是包装类还是基本数据类型都可能会出现上述的异常

博文参考
[url]http://blog.csdn.net/iamlihongwei/article/details/72652384 [/url]

猜你喜欢

转载自mingyundezuoan.iteye.com/blog/2397640