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)
|