轉載:https://blog.csdn.net/u014379639/article/details/90369231
https://blog.csdn.net/qq_29410905/article/details/80325095
mybatis 映射文件中,if標簽判斷字符串相等,兩種方式:
因為mybatis映射文件,是使用的ognl表達式,所以在判斷字符串sex變量是否是字符串Y的時候,
<if test="sex=='Y'.toString()">
<if test = 'sex== "Y"'>
注意:
不能使用
-
<if test="sex=='Y'">
-
and 1=1
- 同時,MyBatis的if、when里面的test表達式對參數進行判斷時,可以調用 java的java.lang.String中定義的方法: 比如:
- < if test= "fwbdh != null and fwbdh != ''">
- <choose> <when test= 'fwbdh.indexOf(",") != -1'> AND t. FWBDH in (${fwbdh}) </when>
- <otherwise> AND t.FWBDH like '%'+#{fwbdh}+ '%' </otherwise> </choose>
