Mybaits传入参数为0时无法识别
2025-11-23 12:07 猎手家园 阅读(5) 评论(0) 收藏 举报1. 在MyBatis中,如果参数类型为Integer或者Long时,传入参数为 0 将默认为 false(为空:例 status = ’’)不生效。
<if test="status != null and status != ''"> and status = #{status} </if>
以上示例中,如果查询条件为:status = 0 时,则不会生效。
2. 解决方案:去除为空字符判断
<if test="status != null"> and status = #{status} </if>
欢迎关注我的公众号:云栖语,不一样的研发视界。

云栖语微信公众号:change-1978
浙公网安备 33010602011771号