9

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.

kkudi
  • 1,625
  • 4
  • 25
  • 47

1 Answers1

10

All you have to do is

<if test="sortBy == 'facility_id' ">
    order by pd.facility_id
</if>
Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
kkudi
  • 1,625
  • 4
  • 25
  • 47
  • @jpganz18: `test` is the attribute of the `if` element which is passing the condition of the test. See the XML tutorial e.g. here: https://www.w3schools.com/xml – Honza Zidek Jul 28 '17 at 14:32