美文网首页
mybatis的 if test 条件判断字符串单双引号解析问题

mybatis的 if test 条件判断字符串单双引号解析问题

作者: 云芈山人 | 来源:发表于2021-08-25 23:02 被阅读0次

mybatis的mapper.xml里通过判断值来选择不同的语句,xml文件部分内容如下:

<where>
  <if test=" contain == '0' " >
    b0114 in (select b0114 from b01 where b0111=#{b0111} and b0194 != '2' )
  </if>
  <if test=" contain == '1' " >
    b0114 in (select b0114 from b01 where b0111 like concat(#{b0111},'%') and b0194 != '2' )
  </if>
</where>

项目跑起来后发现两个都没生效,经过资料查找,最后发现由于MyBatis是使用的OGNL表达式,所以单个的字符要写到双引号里面才行,改为<if test=' contain == "0" ' >或者改为<if test=" contain == '0'.toString() ">,问题解决。

相关文章

网友评论

      本文标题:mybatis的 if test 条件判断字符串单双引号解析问题

      本文链接:https://www.haomeiwen.com/subject/phxjiltx.html