mybatis if判断int类型的查询条件如何判断空和空字符串

来源:互联网 发布:翟姓 名字 知乎 编辑:程序博客网 时间:2024/05/22 09:38

 <if test="null!=state and  state!=''">
state=#{state}
 </if> 

这样state是int类型的数据。这里通过Map传递过来。在这里判断state是否是null和空字符串,当state传过来是0时这个判断是进不了的。


 <if test="null!=state and  state!='' or state==0">
state=#{state}
 </if> 

网上有人说这样写,这样写当state为0时是能正确进入的但是当state为空字符串时判断也进入了。


<if test="null!=state and ''!= state">

state=#{state}

 </if>

所以这样写就可以解决所以问题。

原创粉丝点击