xml转义字符在mybatis动态sql中的使用

一,常用转义字符表 

 &lt;   <  小于号   
 &gt;  >  大于号
 &amp;  &  和
 &apos;  ’ 单引号
 &quot;  " 双引号

 

 

 

 

 

 

二,使用方法示例

        <if test="stardate != null and stardate != ''">
            and u_addtate &gt;= #{stardate}
       </if>

   <if test="enddate != null and enddate != ''"> and u_addtate &lt;#{enddate} </if>

 

三,其他

  1)<![CDATA[ ]]>                   用于声明解析方式,不解析符号

    <![CDATA[  在这里写内容就不需要使用转义字符 ]]>

 

  2)CONCAT('%',#{name},'%')  用于拼接,一般用于模糊查询

    <if test="ckuNumber != null and ckuNumber != ''">
        and u_number LIKE CONCAT('%',#{ckuNumber},'%')
   </if>

 

 

 

 

posted @ 2017-11-30 14:33  言_曦  阅读(2297)  评论(0编辑  收藏  举报