使用mybatis执行SQL语句时有参数出现返回NULL值如何解决
更新:HHH   时间:2023-1-7


今天就跟大家聊聊有关使用mybatis执行SQL语句时有参数出现返回NULL值如何解决,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

原来的写法:

<select id="selectByArticle" parametertype="com.pet.bean.Article" resultmap="com.pet.bean.Article">
  SELECT 
  FROM ARTICLE        
 </select>
<sql id="queryCondition">
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(id)">AND ID = #{id,jdbcType=Integer}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(authorName)">AND AUTHOR_NAME = #{authorName,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(title)">AND TITLE = #{title,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(content)">AND CONTENT = #{content,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(makeTime)">AND MAKE_TIME = #{makeTime,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(updateTime)">AND UPDATE_TIME = #{updateTime,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(kind)">AND KIND = #{kind,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(about)">AND ABOUT = #{about,jdbcType=VARCHAR}</if>
  <if test="@org.apache.commons.lang.StringUtils@isNotBlank(status)">AND STATUS = #{status,jdbcType=VARCHAR}</if>
  </sql>

部分代码:

日志显示:

修改后的写法:resultType改成了resultMap了

<select id="selectByArticle" parametertype="com.pet.bean.Article" resultmap="BaseResultMap">
  SELECT 
  FROM ARTICLE    
 </select>
<resultmap id="BaseResultMap" type="com.pet.bean.Article">
 <id column="ID" jdbctype="INTEGER" property="id">
 <result column="AUTHOR_NAME" jdbctype="VARCHAR" property="authorName">
 <result column="TITLE" jdbctype="VARCHAR" property="title">
 <result column="CONTENT" jdbctype="VARCHAR" property="content">
 <result column="MAKE_TIME" jdbctype="VARCHAR" property="makeTime">
 <result column="UPDATE_TIME" jdbctype="VARCHAR" property="updateTime">
 <result column="KIND" jdbctype="VARCHAR" property="kind">
 <result column="ABOUT" jdbctype="VARCHAR" property="about">
</result></result></result></result></result></result></result></id></resultmap>

日志显示:

看完上述内容,你们对使用mybatis执行SQL语句时有参数出现返回NULL值如何解决有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注天达云行业资讯频道,感谢大家的支持。

返回编程语言教程...