大于号和小于号在xml会被转义,因此在xml中书写需要注意:
两种方案:
**一是:**通过使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析;
但要注意的是:
(1) 此部分不能再包含”]]>”;
(2) 不允许嵌套使用;
(3)”]]>”这部分不能包含空格或者换行。
demo:
--查出id大于2的所有记录
select * from table where id >2;
--mybatis的写法
select * from table where id <![CDATA[>]]> 2;
**二是:用转义字符代替
常见的转义字符有:
在XML中,需要转义的字符有:
(1)& &
(2)< <
(3)> >
(4)" "
(5)' '
demo:
--查出id大于2的所有记录
select * from table where id >2;
--mybatis的写法
select * from table where id < 2;