mybatis 如何通过resultMap 返回long
短信预约 -IT技能 免费直播动态提醒
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来进行判断!
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341