转载自 https://blog.csdn.net/xxlian1201/article/details/52759349
在使用 MyBatis if 进行条件判断时,一直报错:
-
< if test= “fwbdh != null and fwbdh == ‘BAK’”>
-
fwbdh=#{fwbdh}
-
< if>
- 1
- 2
- 3
MyBatis是使用的OGNL表达式来进行解析的,改成:
-
< if test= ‘fwbdh != null and fwbdh == “BAK”’>
-
fwbdh=#{fwbdh}
-
< if>
- 1
- 2
- 3
同时,MyBatis的if、when里面的test表达式对参数进行判断时,可以调用 java的java.lang.String中定义的方法:
比如:
-
< if test= “fwbdh != null and fwbdh != ‘’”>
-
<when test= ‘fwbdh.indexOf(“,”) != -1’>
-
AND t. FWBDH in (${fwbdh})
-
AND t.FWBDH like ‘%’+#{fwbdh}+ ‘%’
-
</ if>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10