zoukankan      html  css  js  c++  java
  • MyBatis中<if test=" ">标签条件不起作用

    问题产生?

      今天在做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 这个问题网上看了很多解决方法,但是测试了都是一个样,目前我还没有找到解决办法,不知道有没有人知道告知下。我现在的解决方法是将我要判断的int类型的数据修改为String类型,
    因为String类型相当于通用的类型,并不会影响之前的数据。等以后有时间了再好好研究下。
  • 相关阅读:
    Leetcode 811. Subdomain Visit Count
    Leetcode 70. Climbing Stairs
    Leetcode 509. Fibonacci Number
    Leetcode 771. Jewels and Stones
    Leetcode 217. Contains Duplicate
    MYSQL安装第三步报错
    .net 开发WEB程序
    JDK版本问题
    打开ECLIPSE 报failed to load the jni shared library
    ANSI_NULLS SQL语句
  • 原文地址:https://www.cnblogs.com/lxwt/p/9628680.html
Copyright © 2011-2022 走看看