五、SpringBoot2.x配置全局異常返回自定義頁面
簡介:使用SpringBoot自定義異常和錯誤頁面跳轉實戰
一、返回自定義異常界面,須要引入thymeleaf依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
二、resource目錄下新建templates,並新建error.html
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("error.html");
modelAndView.addObject("msg", e.getMessage());
return modelAndView;
https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-error-handling
html
首先須要添加模板引擎的Thymeleaf
spring