other than == and != what other logic operators are allowed in <if test="xx operator yy>?

890 views
Skip to first unread message

Simon

unread,
Jul 27, 2010, 9:23:19 AM7/27/10
to mybatis-user
This works:

<select "id=select" resultType="someType">
select * from sometable
<where>
<if test="id != null">
id = #{id}
</if>
</where>
</select>

but this not (because of xml syntax conflict)

<if test="id > 0">
id = #{id}
</if>

1) does the <if> construct only suppot "==" and "!="?
Is ther a way of doing >, <, >=, <= etc?

2) does it support "or" and bracketed logic?

one example in the usergude has "and":
<when test="author != null and author.name != null">

Im guessing that "or" works, but not sure if you can do brackeded
logic, e.g:

<when test="(author != null and author.name != null) or
somethingelse == true" >

thanks,

Larry Meadors

unread,
Jul 27, 2010, 9:28:35 AM7/27/10
to mybati...@googlegroups.com
It's ognl in xml.

http://www.opensymphony.com/ognl/

I think &lt; or &gt; should work just fine.

Larry

Brandon Goodin

unread,
Jul 27, 2010, 9:59:10 AM7/27/10
to mybati...@googlegroups.com
You can also use:

 <if test="id lt 0">

     id = #{id}
 </if>

gt, lt, eq, ne are the same as >, <, ==, !=

Brandon

Brandon Goodin

unread,
Jul 27, 2010, 10:01:32 AM7/27/10
to mybati...@googlegroups.com
Correction to my last post:

You can also use:

 <if test="id lt 0">
     id = #{id}
 </if>

gt, lt, eq, neq are the same as >, <, ==, !=
Reply all
Reply to author
Forward
0 new messages