欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mybatis中使用大于小于等于的正确方法

程序员文章站 2022-06-28 15:06:28
在mybatis中sql是写在xml映射文件中的,如果sql中有一些特殊字符的话,在解析xml文件的时候就会被转义,如若不希望被转义,那该怎么办呢?方法一:使用特殊转义字符例如,>=开始日期 并...

在mybatis中sql是写在xml映射文件中的,如果sql中有一些特殊字符的话,在解析xml文件的时候就会被转义,如若不希望被转义,那该怎么办呢?

方法一:使用特殊转义字符

例如,>=开始日期 并且<=结束日期

&gt;  >  大于号 

&lt;  <  小于号 

   <if test="searchtimebegin != null and searchtimebegin != ''">
       and tcci.consume_time &gt;= concat(#{searchtimebegin},' 00:00:00')
   </if>
   <if test="searchtimeend != null and searchtimeend != ''">
       and tcci.consume_time &lt;= concat(#{searchtimeend},' 23:59:59')
   </if>

方法二:使用<![cdata[ ]]>符号

这里面的内容将不被解析

    <if test="begintime!=null">
      and date (os.show_start_time) >= date(#{begintime})
    </if>
    <if test="endtime!=null">
      and date (os.show_start_time) <![cdata[<=]]> date(#{endtime})
    </if>

在mybatis中<=不能使用,需要使用上面任意一种方法转义,但是>=可以使用!

到此这篇关于mybatis中使用大于小于等于的正确方法的文章就介绍到这了,更多相关mybatis 大于小于等于内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!