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

2019/03/21 by Jinyang | Filed under Uncategorized.
org.apache.ibatis.binding.BindingException: Mapper method 'cn.Mapper.findCouponIdListByFacadeid attempted to return null from a method with a primitive return type (int). 


select 语句应该返回一个int字段,但是返回了一个空的结果集,所以代码就报错了,
修正方法
修改sql语句保证任何时候都返回一个int☞

ifnull(sum(字段),0) as 字段

sum函数保证了肯定有一行记录,但是可能是null
ifnull再进一步转换一个默认值或异常值



Leave a Reply

Your email address will not be published. Required fields are marked *

返回顶部