mybatis的mapper文件的大于号特殊符号使用

第一种方法:

用了转义字符把>和<替换掉,然后就没有问题了。

 

SELECT * FROM test WHERE 1 = 1 AND start_date  &lt;= CURRENT_DATE AND end_date &gt;= CURRENT_DATE

 

附:XML转义字符



                     &lt;                                 

                     <

                     小于号                                           

                     &gt;

                     >                                      

                     大于号

                     &amp;

                     &

                     和

                     &apos;

                     ’

                     单引号

                     &quot;

                     "

                     双引号

 

 

 

第二种方法:

 

 

 

因为这个是xml格式的,所以不允许出现类似“>”这样的字符,但是都可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析 
你的可以写成这个: 

mapper文件示例代码
[html] view plain copy
 
  1. <![CDATA[ when min(starttime)<='12:00' and max(endtime)<='12:00' ]]>     

在mybatis 的mapper配置文件sql语句中, 有时用到 大于, 小于等等的比较, 直接写在里面就被当做标签的开头来处理了, 所以不可.现在又2种解决方法:

一, 用<![CDATA[   ]]>标识,例如:

 

[html] view plain copy
  1. <if test="menu.authority != null">  
  2.     <![CDATA[ and authority < #{menu.authority}]]>  
  3. </if>  

其中不但能用大于'>', 小于'<',          小于等于'<=', 大于等于'>=' 也是可以的.

 

二, 转义, 例如:

 

 

[html] view plain copy
  1. <if test="menu.authority != null">  
  2.     and authority &lt; #{menu.authority}  
  3. </if>  

如此这般......

 

同样可以可以和等号'='一起来使用, 来表示大于等于, 小于等于等.如

 

[html] view plain copy
  1. <if test="menu.authority != null">  
  2.     and authority &gt;= #{menu.authority}  
  3. </if>  

 

posted @ 2017-08-17 15:36  小虾米的java梦  阅读(4593)  评论(0编辑  收藏  举报