Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare strings in mybatis 3 with if statement - dynamic sql

Tags:

ibatis

mybatis

In myBatis 3 how do you compare a string when using dynamic sql?

With iBatis previously you could do the following:

        <isEqual property="sortBy" compareValue="portfolio_id">order by p.portfolio_id</isEqual>

Now with myBatis can you do the following:

        <if test="sortBy.equals('facility_id')">
          order by pd.facility_id
        </if>

sortBy is a property in the parameter map and "facility_id" is the value

I'm a little bit confused as it was straight forward in ibatis.

like image 262
kkudi Avatar asked Feb 14 '12 17:02

kkudi


1 Answers

All you have to do is

<if test="sortBy == 'facility_id' ">
    order by pd.facility_id
</if>
like image 85
kkudi Avatar answered Nov 16 '22 01:11

kkudi