speree

今天使用mybatis开发公司中台项目踩的一个坑,分享并记录一下

踩坑前因:因项目中比较多状态字段,用了大量的Integer 0和1进行判断

在功能做完后只是粗略的点了下觉得没多大问题(来自程序员强大的自信),便提交了代码,很不巧的是刚好领导在做功能测试,发现了功能缺陷,主角来了:

在做牧户查询时所有的0判断均无效,而1有效。查阅资料得知在if语句做如下判断时intger类型0也视为false

<if test="status != null and status !=''">and status = #{status}</if> 

解决方案有二:

1、<if test="status != null ">and status = #{status}</if> 直接判断!=null即可,只有字符串才需要判断!=""。

2、或者这样写 <if test="status != null and status !='' or status==0 ">and status = #{status}</if

 

附上大神详细解析链接:https://www.jianshu.com/p/91ed365c0fdd

相关文章:

  • 2021-08-17
  • 2021-10-09
  • 2021-11-18
  • 2021-12-10
  • 2021-06-16
  • 2021-05-10
  • 2021-05-27
  • 2021-05-25
猜你喜欢
  • 2021-10-23
  • 2021-11-01
  • 2021-11-21
  • 2021-12-06
  • 2021-09-26
  • 2021-08-13
  • 2021-11-17
  • 2021-04-17
相关资源
相似解决方案