zoukankan      html  css  js  c++  java
  • 关于mybatis返回值resultType为空的问题

    假设数据库中一个user表 此时只有id为1的数据,当我们查询id为2的年龄时的时候返回值为null

    但是在mybatis中预定义UserMapper.xml中

    <select id="findUserAgeById" parameterType="int" resultType="int">
    SELECT user.age  FROM user WHERE id = #{id}
    </select>

    此时会报错:attempted to return null from a method with a primitive return type (int)

    改正之后的select语句为

    <select id="findUserAgeById" parameterType="int" resultType="int">
    SELECT IFNULL(max(news.userid),0) FROM news WHERE id = #{id}
    </select>

    这样就会使返回的null变成0,此时返回值为0,不报错。

    在 IFNULL(max(news.userid),0)这段代码中,0可以改成你想要的数据。

  • 相关阅读:
    eclipse(java windows)
    Tomcat(Linux)
    Tomcat(Windows)
    MySql(Windows)
    Java EE API
    计算机网络-TCP三次握手理解
    onclick 和click 的区别
    js轮播图代码
    JS轮播图制作
    js动画原理
  • 原文地址:https://www.cnblogs.com/5aixin/p/10636019.html
Copyright © 2011-2022 走看看