mybatis的<if test> 条件判断

来源:互联网 发布:大数据安全管理办法 编辑:程序博客网 时间:2024/04/20 13:19

在使用 MyBatis if 进行条件判断时,一直报错:

<if test="fwbdh != null and fwbdh == 'BAK'">    fwbdh=#{fwbdh}<if>

MyBatis是使用的OGNL表达式来进行解析的,改成:

<if test='fwbdh != null and fwbdh == "BAK"'>    fwbdh=#{fwbdh}<if>

同时,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> </if>


0
0 0
原创粉丝点击