mybatis 关于 if test 判断字符串的大坑

转载:https://blog.csdn.net/u014379639/article/details/90369231

https://blog.csdn.net/qq_29410905/article/details/80325095

mybatis 映射文件中,if标签判断字符串相等,两种方式:
因为mybatis映射文件,是使用的ognl表达式,所以在判断字符串sex变量是否是字符串Y的时候,

  1.  
<if test="sex=='Y'.toString()">
  1.  
<if test = 'sex== "Y"'>

注意:
不能使用

    1.  
      <if test="sex=='Y'">
    2.  
      and 1=1
  1. 同时,MyBatis的if、when里面的test表达式对参数进行判断时,可以调用 java的java.lang.String中定义的方法: 比如: 
  2. < if test= "fwbdh != null and fwbdh != ''">
  3. <choose> <when test= 'fwbdh.indexOf(",") != -1'> AND t. FWBDH in (${fwbdh}) </when>
  4. <otherwise> AND t.FWBDH like '%'+#{fwbdh}+ '%' </otherwise> </choose> 
posted @ 2020-10-14 21:39  路要一步一步走  阅读(1031)  评论(0编辑  收藏  举报