Springmvc interceptor usage summary, springmvc Summary
/**
*
*
*
*The role of the Interceptor:
* Each request can be intercepted before it reaches the Controller or before each response arrives at the view.
* 1. Global log (who submitted the request and what to do)
* 2. permission management (each request can determine the permission)
*Code:
* Write a class to implement the springframework. web. servlet. HandlerInterceptor interface.
* Pre-Request Interception (Controller not executed yet)
* After the postHandle controller is executed, actions that can be added before the view is generated (adding public parts of the model, such as copyright information)
* AfterCompletion releases resources. For example, if the database link is opened in pre, you can disable it here.
*
* These three methods can be selected based on the business. If they are not true, you can simply write the code.
*
*
*Set interceptor chain
* <Mvc: interceptors>
* <Mvc: interceptor>
* <Mvc: mapping path = ""/> optional. If this parameter is not specified, all requests are intercepted by default. If this parameter is specified, only requests in certain modes are blocked.
* Example: <mvc: mapping path = "/user/*"/> eg: intercept all requests under user/
* <Bean class = "com. my. common. MyInterceptor"> </bean>
* </Mvc: interceptor>
*
* <Mvc: interceptor> the second part of the interceptor chain
* </Mvc: interceptor>
*
* </Mvc: interceptors>
*
Process
1 request along interceptor ① -- interceptor ②... The preHandle method of interceptor N is executed and finally reaches the controller.
2. After the controller is executed, execute interceptor N -- interceptor N-1... until the view is generated .... Interceptor ② --- the postHandle method in interceptor ①.
*
*/