SpringBoot 整合 MyBatis 出现 `BindingException: Mapper method attempted to return null from a method with a primitive return type` 错误的解决方法
根据错误信息,可以看到报错是因为在一个使用原始返回类型(int)的方法中,尝试返回了 null。具体是在 org.example.dao.AdminDao.deletById 方法中出现的问题。
解决方法是确保 deletById 方法不返回 null。你可以在此方法中添加逻辑,以确保它始终返回一个有效的 int 值。
例如,你可以在 deletById 方法中添加一个条件,如果删除操作成功,则返回 1,否则返回 0。这样可以避免返回 null。
@Delete("delete from admin where id = #{id}")
int deletById(Integer id);
另外,你还可以检查是否在 AdminDao 类的 deletById 方法上使用了正确的 MyBatis 注解,以确保方法的签名和返回类型正确匹配。
如果以上方法仍然无法解决问题,你可以查看 MyBatis 的日志,以获取更多有关错误的详细信息。
原文地址: https://www.cveoy.top/t/topic/o7ei 著作权归作者所有。请勿转载和采集!