Skip to content

StringUtils.EMPTY

StringUtils.EMPTY为StringUtils的一个静态常量,值为null

当返回登录信息时需要将密码信息置为null

在ServerResponse里面我们已经设置了若值为null,则key不进行序列化

为什么不直接user.setPassword(null);呢

使用StringUtils更加安全,同样是赋值为null,当后面错误使用该变量是,直接赋值为null会出现空指针异常

StringUtils则对赋予的null值做了处理,即使使用该变量也不会出现空指针异常

使用StringUtils需要添加依赖项

  <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.12.0</version>
    </dependency>

如有转载或 CV 的请标注本站原文地址