mybatis if test 之 0当做参数传入出问题

╰半橙微兮° 2022-04-12 13:40 363阅读 0赞

mybatis的参数传入为Integer的0的时候会把0当做空处理掉

要判断0必须写成下面这样

  1. <where>
  2. <if test="name!=null and name!=''">
  3. AND mi.name like CONCAT('%',#{name},'%')
  4. </if>
  5. <if test="telephone!=null and telephone!=''">
  6. AND mi.telephone = #{telephone}
  7. </if>
  8. <if test="status!=null and status!='' or 0 == status">
  9. AND rs.status = #{status}
  10. </if>
  11. <if test="applicationTimeStart!=null and applicationTimeEnd!=null">
  12. and rs.update_time >= #{applicationTimeStart} and rs.update_time <
  13. DATE_ADD(#{applicationTimeEnd},INTERVAL 1 DAY)
  14. </if>
  15. </where>

如果传入的参数是String字符串的0,则不需要加 or 0==status

发表评论

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

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

相关阅读