This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24672|Reply: 0

[Source] Spring Boot's HandlerInterceptor interceptor

[Copy link]
Posted on 7/23/2021 6:50:36 PM | | |
Application scenarios

1. Logging, which can record the log of requested information for information monitoring, information statistics, PV (Page View) calculation, etc.
2. Permission check: For example, the login detection will enter the processor to detect whether it is logged in, if it does not return directly to the login page.
3. Performance monitoring: sometimes the system is inexplicably slow for a certain period of time, and the interceptor can record the start time before entering the processor and the end time after processing, so as to obtain the processing time of the request (if there is a reverse proxy, such as Apache can be automatically recorded);

4. General behavior: read the cookie to get the user information and put the user object into the request, so as to facilitate the subsequent process, as well as extracting Locale, Theme information, etc., as long as it is required by multiple processors, it can be implemented with interceptors.

5. OpenSessionInView: For example, Hibernate opens the session when entering the processor and closes the session after completion.

It is also AOP (facet-oriented programming), which means that all functions that meet the cross-cutting concern can be implemented in the interceptor.

HandlerInterceptor interface

Create a new TestFilter class inheritanceHandlerInterceptorInterface or rulesHandlerInterceptorAdapterAbstract class

Rewrite the methods you need

Create a new WebAppConfigurer to implement the WebMvcConfigurer interface
(End)




Previous:CentOS 7 installs KubeSphere in All-in-One mode
Next:Modify the MAC address source code
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com