【ruoyi-cloud】解决mybatis在xml文件sql语句中if判断语句传入数值0判断为 false的BUG
·
问题描述
使用mybatis在xml文件sql语句中if判断语句传入数值0判断为 false
<if test="level != null and level != ''">
解决方案:
当传入的 level 值为 0 时,虽然 0 != null 为 true,但是 0 != ‘’ 在MyBatis的OGNL表达式中会被认为是 false,因为:
数字 0 在OGNL中会被转换为布尔值 false
空字符串 ‘’ 也被认为是 false
因此 0 != ‘’ 实际上是 false != false,结果为 false
判断条件修改 and (level != ‘’ or level == 0)
<if test="level != null and (level != '' or level == 0) ">
更多推荐



所有评论(0)