mybatis resultMap返回long mybatis 怎样通过resultMap 返回long
qq_16055765 人气:3想了解mybatis 怎样通过resultMap 返回long的相关内容吗,qq_16055765在本文为您仔细讲解mybatis resultMap返回long的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:mybatis,resultMap,resultMap返回long,下面大家一起来学习吧。
mybatis resultMap 返回long
<resultMap id="ResultOfLong" type="java.lang.Long"> <result column="budget" property="budget" javaType="long"/> </resultMap>
mybatis long 类型返回为null报异常
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来进行判断!
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
加载全部内容