码迷,mamicode.com
首页 > 其他好文 > 详细

@ContrllerAdvice全局异常

时间:2019-12-22 10:27:47      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:strong   poi   lib   ice   ping   style   nav   artifact   map   

@ControllerAdvice,是Spring3.2提供的新注解,它是一个Controller增强器,可对controller中被 @RequestMapping注解的方法加一些逻辑处理。最常用的就是异常处理,需要搭配@ExceptionHandler使用

? ?

@ExceptionHandler 注解用来指明异常的处理类型,即如果指定为 NullpointerException,则数组越界异常就不会进到这个方法中来

? ?

? ?

? ?

@ControllerAdvice使用方法

? ?

首先在SpringBoot中导入thymeleaf的依赖

? ?

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

? ?

其次在SpringBoot项目的templates文件夹中创建一个thymeleaf的html

技术图片

? ?

技术图片

导入上图红框的依赖就可以使用thymeleaf的语法了!

? ?

技术图片

@ContrllerAdvice全局异常

标签:strong   poi   lib   ice   ping   style   nav   artifact   map   

原文地址:https://www.cnblogs.com/fernfei/p/12079060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!