myBatis 返回 int 类型时,报 null 异常

来源:互联网 发布:汤晓燕网络书法展 编辑:程序博客网 时间:2024/05/21 07:48

写了一个下面的SQL,用来check time 在表中存不存在的:

<select id="checkTimeExist" resultType="int">  SELECT    1  FROM    dual  WHERE    EXISTS (      SELECT        1      FROM        `performance` AS p      WHERE        p.`stat_time` = #{time}    )</select>

我把返回值设为了 resultType=”int” ,结果在查询不到结果时,报了下面的异常:

 org.apache.ibatis.binding.BindingException: Mapper method 'com.test.persistence.PerformanceMapper.checkTimeExist attempted to return null from a method with a primitive return type (int).    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:83) ~[mybatis-3.4.0.jar:3.4.0]    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) ~[mybatis-3.4.0.jar:3.4.0]    at com.sun.proxy.$Proxy38.checkTimeExist(Unknown Source) ~[?:?]    ...

看来就只能把 返回值 类型 改成 Integer 来解决这个问题了。

0 0
原创粉丝点击