您的位置:首页 > 其它

在mybatis中怎么表示大于和小于

2019-08-10 16:38 1316 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_37745636/article/details/99083932

当我们要查询一个姓张的且年龄大于25的人群时:
xml中的写法

<where>
<if test="name != null and name != ''">
and name like concat(#{name}, '%')
</if>

<if test="age != null and age != ''">
and age > 25
</if>
</where>

接口中的写法

public List findUsersByName(@Param(“name”) String name, @Param(“age”) Integer age);

但是这种方法会报错,因为在xml文件中<>是作为括号存在的。

正确的做法是将这些符号转成

< > <= >=
&lt; &gt; &lt;= &gt;=
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: