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

待我称王封你为后i 2022-09-03 05:13 77阅读 0赞

场景

报错信息:
attempted to return null from a method with a primitive return type (int).

解决方案

这个报错一般出现在mybatis的update语句中,可能的原因:
1、方法返回类型不对,要用int不要用Integer,int即使没有匹配到,默认值是0。

  1. Integer updateUser(User); // 错误
  2. int updateUser(User); // 正确

2、mybatis标签写的不对,例如<update>标签错写为<select>标签。

  1. <select id="updateUser" parameterType="com.test.User">
  2. update t_user
  3. set flag ='1' where user_account =#{userAccount}
  4. </select>

笔者很可笑,出的错为第二种,光知道copy了,以后要细心。

发表评论

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

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

相关阅读