本文介绍了如何使用if语句将mybatis 3中的字符串进行比较-动态SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在myBatis 3中,使用动态SQL时如何比较字符串?
In myBatis 3 how do you compare a string when using dynamic sql?
以前,使用iBatis,您可以执行以下操作:
With iBatis previously you could do the following:
<isEqual property="sortBy" compareValue="portfolio_id">order by p.portfolio_id</isEqual>
现在,使用myBatis可以执行以下操作:
Now with myBatis can you do the following:
<if test="sortBy.equals('facility_id')">
order by pd.facility_id
</if>
sortBy是参数图中的属性,而"facility_id"是值
sortBy is a property in the parameter map and "facility_id" is the value
我有点困惑,因为它在ibatis中是直截了当的.
I'm a little bit confused as it was straight forward in ibatis.
推荐答案
您所要做的就是
<if test="sortBy == 'facility_id' ">
order by pd.facility_id
</if>
这篇关于如何使用if语句将mybatis 3中的字符串进行比较-动态SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!