mybatis传入的值为0时的判断

「爱情、让人受尽委屈。」 2024-04-17 20:12 194阅读 0赞

mybatis判断是否为空一般为:

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

但是如果传入的值为0,就不运行该条,因为mybatis默认0和””相等,要解决这个问题,可以把代码改为:

  1. <if test="state!=null and state!='' or state==0">state = #{state},</if>
  2. //或者把判断是否为空字符串去掉,变为:
  3. <if test="state!=null">state = #{state},</if>

或者将0转化为String类型,也可以解决该问题

发表评论

表情:
评论列表 (有 0 条评论,194人围观)

还没有评论,来说两句吧...

相关阅读