mybatis在使用<if>动态标签时传参为0的问题

项目的数据库设置的字段hotel_stopped为int类型,hotel_stopped=0 为已审核,1为已删除,2为未审核。。 

做查询的时候要把hotel_stopped作为可选条件

<if test="null!=hotelStopped and ''!=hotelStopped ">
    AND hotel_stopped=#{hotelStopped}
</if>

然而发现查询的时候数据总是不对,当条件为空,查询全部可以,查询0出来的还是全部。

在网上查询也知道原因,是mybatis自动把0当作空来处理。

按照网上的办法,在后面再加条件或把判空删除。如下:

​<!--1-->
<if test="null!=hotelStopped and ''!=hotelStopped or 0==hotelStopped">
    AND hotel_stopped=#{hotelStopped}
</if>

<!--2-->
<if test="null!=hotelStopped and (hotelStopped==0 ? '0' : hotelStopped)">
    AND hotel_stopped=#{hotelStopped}
</if>

<!--3-->
<if test="null!=hotelStopped">
    AND hotel_stopped=#{hotelStopped}
</if>

查询0可以了,但是查询全部又变成查询0的结果了。

最后把hotelStopped类型改成Integer。使用第2个格式。。解决了问题。。。。- - 

感谢:https://blog.csdn.net/jayke512/article/details/50266969

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值