如果在控制器中发生异常,我想写一些消息来响应。要做到这一点,我需要响应对象。我可以静态访问当前响应/请求对象,或者我必须将此对象传递给异常,如jsf (FacesContext.getCurrentInstance()getExternalContext()的GetResponse());
List<View_Probes> getAllProbes(HttpServletResponse response) throws ResourceNotFoundException{
try {
List<Probe> probes= inseptraPersistenceService.listAllProbes();
List<View_Probes> result= mapper.mapAll(probes, View_Probes.class);
return result;
} catch (Exception e) {
throw new ResourceNotFoundException(e);
}
}
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
public ResourceNotFoundException() {
}
public ResourceNotFoundException(Throwable e) {
super(e);
}
}