Java Spring Boot VS. Netcore (10) Java Interceptor vs. Netcore Interceptor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.