背景:

在使用mybatis进行查询时,有个字段为null,报了空指针异常的错误。

一直以为是判断的问题,没判断到,想了很多办法,一直没解决。

 	<if test="status!= null">
 	    and a.status=#{status}
 	</if>

解决方法 

发现是因为在dao接口类的方法里面参数的类型为 int。

	List<Map<String, Object>>  listMyLessonPage(@Param("userID")int userID,@Param("status")int status);

所以将int改为integer类型,问题解决。

是否是这儿发生了类型强转,当这个值为null时,进行类型转换的时候就会报空指针异常(int没有null)

查阅资料后说是:

由于参数出现了null值,对于Mybatis,如果进行操作的时候,没有指定jdbcType类型的参数,mybatis默认jdbcType.OTHER导致,给参数加上jdbcType可解决(注意大小写)。

参考:https://blog.csdn.net/fishernemo/article/details/27649233

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案