Mybatis 的特殊字符转义

XML 文件在解析时会将五种特殊字符进行转义,当不希望语法被转义时,就需要进行特别处理。

Myabtis 中五个特殊字符
原始符号 符号含义 > 大于 < 小于 & and " 英文双引号 ’ 英文单引号

方法一:<![CDATA[ ]]>

<select id="select" resultMap="user">   
     select * from user where age <![CDATA[ > ]]> 18
</select>

方法二:使用转义字符

<select id="select" resultMap="user">   
     select * from user where age &gt; 18
</select>
原始字符 转义字符 Tips > &gt 转义字符尾部需要添加英文分号 < &lt 转义字符尾部需要添加英文分号 & &amp 转义字符尾部需要添加英文分号 " &quot 转义字符尾部需要添加英文分号 ’ &apos 转义字符尾部需要添加英文分号
经验分享 程序员 微信小程序 职场和发展