欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mybatis long 类型返回为null报异常

程序员文章站 2022-07-01 07:53:51
...
 Mapper method 'com.mpn.dao.TWeatherMapper.avgWeatherTemperature attempted to return null from a method with a primitive return type (long).
  <select id="avgWeatherTemperature" resultType="java.lang.Long" parameterType="java.lang.String" >
        SELECT IFNULL(AVG(WeatherTemperature),0) AS OrderAverage FROM t_weather WHERE WeatherDate= #{date,jdbcType=VARCHAR};
  </select>
  
   <select id="sumWeatherRainfall" resultType="java.lang.Long" parameterType="java.lang.String" >
        SELECT SUM(WeatherTemperature) AS OrderAverage FROM t_weather WHERE WeatherDate= #{date,jdbcType=VARCHAR};
  
  </select>
  
   <select id="avghumidity" resultType="java.lang.Long" parameterType="java.lang.String" >
        SELECT IFNULL(AVG(WeatherHumidity),0) AS OrderAverage FROM t_weather WHERE WeatherDate= #{date,jdbcType=VARCHAR};
  </select>

由于返回为空long中没有此类型所以抛异常,改为

 <!-- 根据日期来进行计算平局值与 -->
   <select id="avgWeatherTemperature" resultType="java.lang.Long" parameterType="java.lang.String" >
        SELECT IFNULL(AVG(WeatherTemperature),0) AS OrderAverage FROM t_weather WHERE WeatherDate= #{date,jdbcType=VARCHAR};
  </select>
  
   <select id="sumWeatherRainfall" resultType="java.lang.Long" parameterType="java.lang.String" >
        SELECT IFNULL(SUM(WeatherTemperature),0) AS OrderAverage FROM t_weather WHERE WeatherDate= #{date,jdbcType=VARCHAR};
  
  </select>
  
   <select id="avghumidity" resultType="java.lang.Long" parameterType="java.lang.String" >
        SELECT IFNULL(AVG(WeatherHumidity),0) AS OrderAverage FROM t_weather WHERE WeatherDate= #{date,jdbcType=VARCHAR};
  </select>

用IFNULL来进行判断

相关标签: mybatis