attempted to return null from a method with a primitive return type (int).
2017-05-23 17:33
736 查看
<select id="getMaxHitEventId" parameterType="string" resultType="int"> select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV} </select>mybatis+mysql查询出来会报如下错误:
attempted to return null from a method with a primitive return type (int).
我的返回值类型为int,但是查询出来的结果有空值,所以会出现如上的异常,以下为解决办法:
1.当查询出来为空时,给赋值一个默认值:
select IFNULL(max(app_hitEventID),0) from hits_tab_app where app_hitV=#{app_hitV}
2.将返回值类型改为Integer,然后由业务代码去进行判断:
<select id="getMaxHitEventId" parameterType="string" resultType="Integer"> select max(app_hitEventID) from hits_tab_app where app_hitV=#{app_hitV} </select>
相关文章推荐
- 关于attempted to return null from a method with a primitive return type (int).报错解决方案
- mybatis -----attempted to return null from a method with a primitive return type (int)
- [置顶] 【java】Mybatis返回int类型为空时报错 attempted to return null from a method with a primitive return type (int)
- attempted to return null from a method with a primitive return type (int)异常的解决
- delete attempted to return null from a method with a primitive return type (int)
- MyBatis提示getFundBonus attempted to return null from a method with a primitive return type (double)
- mybatis返回int类型报错 return null from a method with a primitive return type (int).
- aop.AopInvocationException: null return value from advice does not match primitive return type for
- Spring之AOP奇葩报错:Null return value from advice does not match primitive return type for
- 关于Hibernate中的int和float数据及Null value was assigned to a property of primitive type setter of
- Null value was assigned to a property of primitive type setter ,hibernate int型数据无法读取 hiberante读int
- BUG6:Cannot return a value from a method with void result type 返回值错误
- MyBatis Error:BindingException Mapper method attempted to return null
- 关于Attempt to invoke virtual method 'HSSFCell.getCellType(int)'' on a null object reference
- return anonymous type from method.
- Null value was assigned to a property of primitive type setter of
- 问题描述:Null value was assigned to a property of primitive type setter
- Null value was assigned to a property of primitive type setter of com.superm
- attempted to assign id from null one-to-one property:
- Null value was assigned to a property of primitive type setter问题分析与解决