Mybatis mapper.xml 判断条件写法注意

1.判断String是否为空

<if test="stringParam != null and stringParam != ''"></if>

脚本中:+"<if test='keyword != null and keyword!=\"\"'>"

                "<if test=\"age != null\"> age = #{age}</if>" +

2.判断Integer是否大于0

<if test="idParam !=null and idParam gt 0"></if>

判断等于  <when test=\"item.mark == 1\">"

3.判断List是否不为空

<if test="listParam !=null and listParam.size >0"></if>
4.判断String是否以某特定字符(比如此处的"user")开头
<if test="stringParam.indexOf('user') != -1"></if>

5.判断字符串是否等于特定字符(比如此处的user)

<if test='stringParam != null and stringParam == "user"'></if>
注意不能使用此写法 <if test="stringParam != null and stringParam != 'user'"></if> 即最外边用双引号,里边用单引号,此写法会抱java.lang.NumberFormatException异常
如果要用这个写法要<if test="stringParam != null and stringParam != 'user'.toString()"></if>

6 日期比较

 and  apply_start_time &gt;=#{minDate,jdbcType=TIMESTAMP} 

7 like 的三种写法

        方法一:concat        and name like concat('%',#{name},'%')

        方式二:${}          and exam_type_name like '%${examTypeName}%'

        方式三:#{}         and exam_type_name like "%"#{examTypeName}"%"

8 比较符号

原符号       <        <=      >       >=       &        '        "
替换符号    &lt;    &lt;=   &gt;    &gt;=   &amp;   &apos;  &quot;
例如:sql如下:
create_date_time &gt;= #{startTime} and  create_date_time &lt;= #{endTime}

大于等于
<![CDATA[ >= ]]>
小于等于
<![CDATA[ <= ]]>
例如:sql如下:
create_date_time <![CDATA[ >= ]]> #{startTime} and  create_date_time <![CDATA[ <= ]]> #{endTime}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值