mybatis ![CDATA[ ]] 使用避免特殊字符
一 概述
在Mybatis的xml文件中编写SQL的时候经常会使用类似:< > =等特殊字符,但是在解析xml文件的时候它们会被转义,当我们不希望出现这种情况的时候,我们可以通过加上防止转义的内容:<![CDATA[ ]]>.
上述为xml的语法,在<![CDATA[ ]]>中的内容都会被xml解析器所忽略,此时如果我们将
二 特殊符号转义与转义对比
< | <= | > | >= | & | ‘ | “ |
< | <= | > | >= | & | ' | " |
三 <![CDATA[ ]]>使用**示例**
<if test="startTime != null and startTime.length > 0">
and record.create_time <![CDATA[>=]]> #{startTime}
</if>
<if test="endTime != null and endTime.length > 0">
and record.create_time <![CDATA[<=]]> #{endTime}
</if>
<if test="distributionStartTime != null and distributionStartTime.length > 0">
and crecord.create_time <![CDATA[>=]]> #{distributionStartTime}
</if>
<if test="distributionEndTime != null and distributionEndTime.length > 0">
and crecord.create_time <![CDATA[<=]]> #{distributionEndTime}
</if>
<if test="shouldPayStartTime != null and shouldPayStartTime.length > 0">
and orderinfo.due_time <![CDATA[>=]]> #{shouldPayStartTime}
</if>
<if test="shouldPayEndTime != null and shouldPayEndTime.length > 0">
and orderinfo.due_time <![CDATA[<=]]> #{shouldPayEndTime}
</if>
还没有评论,来说两句吧...