This article is mainly about the handling of interceptors, here is the next org.springframework.web.servlet under the Handlerinterceptor
Java Interceptor
Look at the code through the Handlerinterceptor class
Public Interface handlerinterceptor { booleanthrows Exception; void throws Exception; void throws Exception;}
Interceptor processing is in, three methods of the meaning of a look to understand, do not do too much introduction
So what do we do with this in the code?
This is also combined with the previous section of the filter interface in the processing, what to intercept, filtering out the interception Handlerinterceptor interface method to intercept, Myhandlerinterceptor extends Handlerinterceptor implementation process slightly ...
Get the interceptor as follows from the previous filter section:
Public classWebmvcconfigextendsWebmvcconfigureradapter {@AutowiredPrivatemyhandlerintercepter myhandlerintercepter; @Override Public voidaddinterceptors (Interceptorregistry registry) {Registry.addinterceptor (myhandlerintercepter). AddPathPatterns ("/**"); Super. Addinterceptors (registry); } @Bean PublicFilterregistrationbean Registfilter () {Filterregistrationbean registration=NewFilterregistrationbean (); Registration.setfilter (NewOpenentitymanagerinviewfilter ()); Registration.addurlpatterns ("/*"); Registration.setorder (1); returnregistration; }
Monitor all the routing addresses on the line, then. Netcore how to deal with it? It's used here. Action in the Netcore to illustrate
. Netcore Interceptor
When executing an action, you need to process the relevant business before and after execution, and look at the code below
Public Virtual void onactionexecuted (ActionExecutedContext context); Public Virtual void OnActionExecuting (ActionExecutingContext context);
Before and after the action executes the above method, through the rewriting of this write method to deal with the business, which is actually similar to Java,. Netcore performs the current onactionexecuting, onactionexecuted method, respectively, before object instance Invoke by creating a Actioncontext object
Of course. Filter in Netcore There are other, just the action action that actionfilter here
Java Spring Boot VS. Netcore (10) Java Interceptor vs. Netcore Interceptor