Spring Boot & Spring MVC におけるエラーの対応サンプルコード
サンプルコード
@RequestMapping(“/error-701")
public String error701(HttpServletRequest request, HttpServletResponse response) throws AnotherException {
throw new AnotherException();
}
@ExceptionHandler(AnotherException.class)
String handleAnotherException(HttpServletRequest request, HttpServletResponse response, Model model)
throws IOException {
//Status Codeを設定
response.setStatus(701);
model.addAllAttributes(errorAttributes.getErrorAttributes(new ServletRequestAttributes(request), true));
return “error/7xx";
}