MyBatis的Mapper.xml文件中处理大于号小于号的方法

由于xml中">"和"<"都是有特殊意义的,所以sql语句中不能再使用">"和"<"符号,就需要进行处理.

比如:

select * from t_doc where create_time < '2023-01-30 11:00:00'

方式一: 使用转义字符替换

符号 符号中文名 转义后的符号
< 小于号 &lt;
> 大于号 &gt;
& &amp;
' 单引号 &apos;
" 双引号 &quot;

使用转义字符替换后为:

select * from t_doc where create_time &lt; '2023-01-30 11:00:00'

方式二: 使用<![CDATA[]]>标记,将其中的内容表示为纯文本

使用<![CDATA[]]>标记后为:

select * from t_doc where create_time <![CDATA[<]]> '2023-01-30 11:00:00'
posted @ 2023-01-30 09:56  安徒生敲代码  阅读(706)  评论(0编辑  收藏  举报