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 转义字符尾部需要添加英文分号

猜你喜欢

转载自blog.csdn.net/qq_39249094/article/details/112874919