原因
由于mybatis编写动态sql时,是基于OGNL语法表达式的。如下图
符号 | 转义字符 | 说明 |
---|---|---|
< | < | 小于 |
<= | <= | 小于等于 |
> | > | 大于 |
>= | >= | 大于等于 |
& | & | 逻辑与 |
‘xxx’ | \apos; | 单引号 |
“xxx” | \quot; | 双引号 |
解决方法
如
select *
from student
<where>
<if test="age != null>
and age < #{age}
</if>
</where>
改成
select *
from student
<where>
<if test="age != null>
and age < #{age}
</if>
</where>