zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Mybatis中Integer类型的判断<if test=“status!= null and status!= ‘‘“>问题

mybatis 类型 and 判断 if null status test
2023-09-27 14:25:32 时间

Mybatis在进行<if test="status!= null and status!= ''">判空操作时,如果status为0的时候,该判断条件的值为false,也就是说Mybatis此时把0作为null来进行判断的

此时就会出现问题,在查询状态是0的数据时,查询的是全部数据

 

解决办法:

将判断条件修改为:<if test="status!= null">

结论:

  1. <if test="status != null">中status为integer类型的,status=0的判断结果为true。
  2. <if test="status != null and status != ''">中status为integer类型的,status=0的判断结果为false,mybatis把status看作string来进行判断。