首页 > 其他 > 详细

MyBatis中<if test=" ">标签条件不起作用

时间:2018-09-11 16:53:10      阅读:1371      评论:0      收藏:0      [点我收藏+]

问题产生?

  今天在做Excel导出的时候,有个判断一个状态的字段,我的这个字段是int类型的,还有两个时间类型,我在判断的时候给的是Long类型的。

在测试的时候发现,不管怎么样都不执行if条件里面的内容,代码如下:

 1 <select id="selectBusinessByHoutaiShenhe" resultMap="BaseResultMap" >
 2     select 
 3     <include refid="Base_Column_List" />
 4     from tb_business
 5     <where>
 6         <if test="starts != null and starts != ‘‘ ">
 7             and starts = #{starts,jdbcType=INTEGER}
 8         </if>
 9         <if test="startTime !=null and startTime != ‘‘ ">
10             and register_time <![CDATA[>= ]]>#{startTime,jdbcType=TIMESTAMP}
11         </if>
12         <if test="endTime != null and endTime != ‘‘ ">
13             and register_time <![CDATA[<= ]]> #{endTime,jdbcType=TIMESTAMP}
14         </if>
15      </where>
16   </select>

一直测试了好几遍发现,不管怎么判断,什么条件都不输入,都会执行  where starts = ? ;让我非常纳闷,同样的方法,为啥那个startTime 和endTime 都不执行呢?

后来我看了下,对比了下,这两种类型不一样,starts为int类型,我修改成如下代码:

 1 <select id="selectBusinessByHoutaiShenhe" resultMap="BaseResultMap" >
 2     select 
 3     <include refid="Base_Column_List" />
 4     from tb_business
 5     <where>
 6         <if test="starts == ‘‘ ">
 7             and starts = #{starts,jdbcType=INTEGER}
 8         </if>
 9         <if test="startTime !=null and startTime != ‘‘ ">
10             and register_time <![CDATA[>= ]]>#{startTime,jdbcType=TIMESTAMP}
11         </if>
12         <if test="endTime != null and endTime != ‘‘ ">
13             and register_time <![CDATA[<= ]]> #{endTime,jdbcType=TIMESTAMP}
14         </if>
15      </where>

starts == ‘ ‘ 如果starts 类型为int类型,应该这样判断。

MyBatis中<if test=" ">标签条件不起作用

原文:https://www.cnblogs.com/lxwt/p/9628680.html

(1)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!