mybatis将传入的Integer类型的0被识别成空字符串,网上的解决办法:
<if test="status != null and status != '' or status == 0">
and status = #{status, jdbcType = INTEGER}
</if>
然而还是有无效的时候。既然status==''时无效,就将其置为null。此时就在Java中对该参数进行处理,当 status == '' 时将其赋值为 null。
1 @PostMapping(value = "/listUser") 2 public Object listUser(@RequestBody Map<String, Object> params) { 3 try { 8 if(("").equals(params.get("status"))) { 9 params.put("status", null); 10 } 11 List<SysUser> listUser = userService.listUser(params); 12 return listUser; 13 } catch (Exception e) { 14 logger.error("获取用户信息异常=====>" + e.getMessage());16 } 17 }
或许还有其它的办法,多多尝试。