1. 程式人生 > >SpringBoot2.x配置全域性異常返回自定義頁面

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;