SpringMVC @ControllerAdvice 注解的官方解释
@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Component
public @interface ControllerAdvice
Indicates the annotated class assists a “Controller”. Serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning.
It is typically used to define @ExceptionHandler, @InitBinder, and @ModelAttribute methods that apply to all @RequestMapping methods.
One of annotations(), basePackageClasses(), basePackages() or its alias value() may be specified to define specific subsets of Controllers to assist. When multiple selectors are applied, OR logic is applied – meaning selected Controllers should match at least one selector.
The default behavior (i.e. if used without any selector), the @ControllerAdvice annotated class will assist all known Controllers.
Note that those checks are done at runtime, so adding many attributes and using multiple strategies may have negative impacts (complexity, performance).
Since: 3.2 Author: Rossen Stoyanchev, Brian Clozel, Sam Brannen
上面的意思是带有@ControllerAdvice
的类,作为@Controller
类 的组成部分,通常用来定义 @ExceptionHandler
, @InitBinder
, 和@ModelAttribute
这样的方法,作用的返回由这个注解的 annotations()
, basePackageClasses()
, basePackages()
或者别名 value()
筛选,如果同时设置了这几个值,因为多个条件之间的关系是 OR的关系,所以满足任何一个条件的 Controller 都会被作用。
相关文章
- 【技术种草】cdn+轻量服务器+hugo=让博客“云原生”一下
- CLB运维&运营最佳实践 ---访问日志大洞察
- vnc方式登陆服务器
- 轻松学排序算法:眼睛直观感受几种常用排序算法
- 十二个经典的大数据项目
- 为什么使用 CDN 内容分发网络?
- 大数据——大数据默认端口号列表
- Weld 1.1.5.Final,JSR-299 的框架
- JavaFX 2012:彻底开源
- 提升as3程序性能的十大要点
- 通过凸面几何学进行独立于边际的在线多类学习
- 利用行动影响的规律性和部分已知的模型进行离线强化学习
- ModelLight:基于模型的交通信号控制的元强化学习
- 浅谈Visual Source Safe项目分支
- 基于先验知识的递归卡尔曼滤波的代理人联合状态和输入估计
- 结合网络结构和非线性恢复来提高声誉评估的性能
- 最佳实践丨云开发CloudBase多环境管理实践
- TimeVAE:用于生成多变量时间序列的变异自动编码器
- 具有线性阈值激活的神经网络:结构和算法
- 内网渗透之横向移动 -- 从域外向域内进行密码喷洒攻击