HandlerInterceptor接口详解

源码:

  1. /**
  2.  * Workflow interface that allows for customized handler execution chains.
  3.  * Applications can register any number of existing or custom interceptors
  4.  * for certain groups of handlers, to add common preprocessing behavior
  5.  * without needing to modify each handler implementation.
  6.  *
  7.  * <p>A HandlerInterceptor gets called before the appropriate HandlerAdapter
  8.  * triggers the execution of the handler itself. This mechanism can be used
  9.  * for a large field of preprocessing aspects, e.g. for authorization checks,
  10.  * or common handler behavior like locale or theme changes. Its main purpose
  11.  * is to allow for factoring out repetitive handler code.
  12.  *
  13.  * <p>In an asynchronous processing scenario, the handler may be executed in a
  14.  * separate thread while the main thread exits without rendering or invoking the
  15.  * {@code postHandle} and {@code afterCompletion} callbacks. When concurrent
  16.  * handler execution completes, the request is dispatched back in order to
  17.  * proceed with rendering the model and all methods of this contract are invoked
  18.  * again. For further options and details see
  19.  * {@code org.springframework.web.servlet.AsyncHandlerInterceptor}
  20.  *
  21.  * <p>Typically an interceptor chain is defined per HandlerMapping bean,
  22.  * sharing its granularity. To be able to apply a certain interceptor chain
  23.  * to a group of handlers, one needs to map the desired handlers via one
  24.  * HandlerMapping bean. The interceptors themselves are defined as beans
  25.  * in the application context, referenced by the mapping bean definition
  26.  * via its "interceptors" property (in XML: a &lt;list&gt; of &lt;ref&gt;).
  27.  *
  28.  * <p>HandlerInterceptor is basically similar to a Servlet Filter, but in
  29.  * contrast to the latter it just allows custom pre-processing with the option
  30.  * of prohibiting the execution of the handler itself, and custom post-processing.
  31.  * Filters are more powerful, for example they allow for exchanging the request
  32.  * and response objects that are handed down the chain. Note that a filter
  33.  * gets configured in web.xml, a HandlerInterceptor in the application context.
  34.  *
  35.  * <p>As a basic guideline, fine-grained handler-related preprocessing tasks are
  36.  * candidates for HandlerInterceptor implementations, especially factored-out
  37.  * common handler code and authorization checks. On the other hand, a Filter
  38.  * is well-suited for request content and view c
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值