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() ">,问题解决。
网友评论