记录自己写项目时遇到的问题二,mybatis条件查询参数为0时没有识别。
根据状态查询时,status为1时可正常过滤符合条件的列表,当status为0时,却发生这样一个问题,他把所有语句都查询出来了,也就是没有进行条件过滤。
<where>
<if test="status != '' and status != null ">
and status = #{status}
</if>
<if test="commodityType != '' and commodityType != null">
and commodity_type = #{commodityType}
</if>
</where>
后来才知道Integer类型值为0时应该这样判断
<if test="status != '' and status != null or status==0">
<where>
<if test="status != '' and status != null or status==0">
and status = #{status}
</if>
<if test="commodityType != '' and commodityType != null">
and commodity_type = #{commodityType}
</if>
</where>