Java/Web中如何更优雅的处理空值

一、问题来源

(1)主要可能是在查询数据库的时候,会返回空对象,那么在没对其处理就直接使用,可能会发生意料之外的灾难。

eg,

    User other = userService.getUserByID(user.getId());
        //用户已存在
        if(other!=null && other.getId().equals(user.getId()))

二、参考博客

https://www.cnblogs.com/niudaben/p/11897961.html

posted @ 2021-01-09 11:33  An_One  阅读(144)  评论(0)    收藏  举报