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>
发布了203 篇原创文章 · 获赞 136 · 访问量 42万+

猜你喜欢

转载自blog.csdn.net/u012045045/article/details/103118200