2012-02-14 69 views
8

在myBatis 3中,如何在使用動態sql時比較字符串?如何使用if語句比較mybatis 3中的字符串 - 動態sql

隨着iBatis的前面,你可以做到以下幾點:

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

現在你可以執行以下操作:

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

sortBy是在參數映射屬性和「facility_id」是值

我有點困惑,因爲它在ibatis中很直接。

回答

7

所有你需要做的就是

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

爲什麼在所有的例子總是有<如果測試....誰是「測試」? – jpganz18 2017-05-04 18:15:53

+0

@ jpganz18:'test'是正在通過測試條件的'if'元素的屬性。請參閱XML教程這裏:https://www.w3schools.com/xml – 2017-07-28 14:32:07