【发布时间】:2019-01-23 08:13:00
【问题描述】:
如何在应用程序中捕获 404 错误并呈现像 index.html 这样的自定义 html?我不想使用 /error 文件夹中的页面。
例如,如果我要求 http://localhost:8080/test 并且没有用于测试的映射,我的应用程序应该在 /resources/template 文件夹中呈现 index.html
谢谢
****编辑****
这样解决了,不好的是即使更改了getErrorPath返回值,我也无法更改请求映射的路径。
@Controller
public class MyCustomErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError() {
return "globalerrorview";
}
@Override
public String getErrorPath() {
return "/error";
}
}
【问题讨论】:
-
您是否使用 thymeleaf / 类似库进行模板化?
-
@akhilRao 是的,抱歉,添加为标签
标签: spring-boot spring-mvc thymeleaf