五、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