SpringBoot2.x配置全局异常返回自定义页面

1、返回自定义异常界面,需要引入thymeleaf依赖
        <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>


    2、resource目录下新建templates,并新建error.html
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error.html");
        modelAndView.addObject("msg", e.getMessage());
        return modelAndView;

猜你喜欢

转载自blog.csdn.net/peng_0129/article/details/85049214