springboot异常处理

1.springboot默认发生异常会跳转到白页

  

 

 

 2.自定义错误页

  我们在templates/error路径下新增404.html和5xxhtml   注意使用 thymeleaf 时候,所有的html文件要添加命名空间

  发生404错误时,我们就会自动跳转到404.html

  发生5xx错误时,我们自动跳转到5xx.html

  

 

3.使用@ControllerAdvice和ExceptionHandler

  使得发生某些特定异常时,实现视图跳转   下图中的异常就是发生数学异常或者空指针异常时候,实现页面跳转到login页面

  

 

 

 

 

  

posted @ 2022-03-03 23:02  qwedfrgh  阅读(56)  评论(0)    收藏  举报