别人也有弄过, 不过有点零碎, 自己整理下.
在mybatis 的mapper配置文件sql语句中, 有时用到 大于, 小于等等的比较, 直接写在里面就被当做标签的开头来处理了, 所以不可.现在又2种解决方法:
一, 用<![CDATA[ ]]>标识,例如:
<if test="menu.authority != null">
<![CDATA[ and authority < #{menu.authority}]]>
</if>其中不但能用大于'>', 小于'<', 小于等于'<=', 大于等于'>=' 也是可以的.
二, 转义, 例如:
<if test="menu.authority != null">
and authority < #{menu.authority}
</if> 如此这般......
同样可以可以和等号'='一起来使用, 来表示大于等于, 小于等于等.如
<if test="menu.authority != null">
and authority >= #{menu.authority}
</if>
本文介绍在MyBatis的Mapper配置文件中如何正确使用大于、小于等符号的方法。通过CDATA标记或转义字符的方式避免这些符号被误解析为XML标签。
7万+

被折叠的 条评论
为什么被折叠?



