MyBatis Mapper method ‘xxx‘ attempted to return null from a method with a primitive return type问题解决

清疚 2022-10-10 12:36 280阅读 0赞

问题描述:

org.apache.ibatis.binding.BindingException: Mapper method ‘com.dao.UserDao.getSum’ attempted to return null from a method with a primitive return type (long).

问题分析:

1、使用sum()函数时如果没有符合where条件的记录会返回null,同时resultType为基本类型,数据绑定时会报错。

  1. <select id="getSum" resultType="long">
  2. SELECT
  3. sum(t.age)
  4. FROM t_user t
  5. WHERE user_id='1'
  6. </select>

解决办法:resultType使用包装类。

  1. <select id="getSum" resultType="java.lang.Long">
  2. SELECT
  3. sum(t.age)
  4. FROM t_user t
  5. WHERE user_id='1'
  6. </select>

发表评论

表情:
评论列表 (有 0 条评论,280人围观)

还没有评论,来说两句吧...

相关阅读