mybatis sql语句配置 符号不兼容 大于号 小于号

在mybatis中对sql语句中涉及到大于号,小于号,如何操作:

方法一、

将其放入到<![CDATA[  ]]>标签中

如:

[html] view plain copy
 
  1. <![CDATA[ 
  2.        and mm.ttime > to_date(#{startDateTime},'yyyy-mm-dd hh24:mi:ss') 
  3.        and mm.ttime <= to_date(#{endDateTime},'yyyy-mm-dd hh24:mi:ss') 
  4. ]]>  

方法二、

如果是在动态语句中,则需要转换

如:

[html] view plain copy
 
  1. <if test="startDateTime!=null"> and mm.ttime &gt; to_date(#{startDateTime},'yyyy-mm-dd hh24:mi:ss')</if>  
  2. <if test="endDateTime!=null"> and mm.ttime &lt;= to_date(#{endDateTime},'yyyy-mm-dd hh24:mi:ss')</if>  

符号:

    &lt;          < 
    &gt;          >  
    &lt;&gt;   <>
    &amp;      & 
    &apos;      '
    &quot;      "

原文地址:https://www.cnblogs.com/tanzq/p/8424713.html