【发布时间】:2015-01-21 16:21:51
【问题描述】:
我的系统有这些类:
PersonBean - handles the requests from the view;
PersonService - provides all operations for the PersonBeam;
PersonDao - provides data access from db to Service classes;
我的PersonDao 类上有一个findById(int personId) 方法。当PersonDao 无法使用提供的Id 找到任何Person 时,它会返回Null。我应该在哪里处理Null?在哪一层?
【问题讨论】:
-
我会处理来自数据层(即实体)和向上(访问层、服务层等)的 NPE。你必须记住,NPE 可以被扔到不同的层,如下所述@mnd