2
我有以下控制器邏輯。但是,如果我導航到一個不存在的頁面(例如/ random-page),最終會出現TemplateInputException。我怎樣才能抓住這個並轉到404頁面?句柄org.thymeleaf.exceptions.TemplateInputException
@RequestMapping(value = { "{path:(?!resources|error).*$}", "{path:(?!resources|error).*$}/**" }, headers = "Accept=text/html")
public String index(final HttpServletRequest request) {
try {
String path = (String) request.getAttribute(
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
return path.split("/")[1];
} catch (Exception e) {
log.error("Failed to render the page. {}",e);
return "error/general";
}
}
Thymeleaf似乎忽略的ExceptionHandler:
@ExceptionHandler(Exception.class)
public ModelAndView handleAllException(Exception ex) {
ModelAndView model = new ModelAndView("error/generic_error");
model.addObject("errMsg", "this is Exception.class");
return model;
}
有你找到了解決辦法然而? – Kousalik