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

孤人 提交于 2020-01-03 07:29:19

问题


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.


回答1:


All you have to do is

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


来源:https://stackoverflow.com/questions/9281269/how-to-compare-strings-in-mybatis-3-with-if-statement-dynamic-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!