Springmvc interceptor usage summary, springmvc Summary

Source: Internet
Author: User

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 ①.
*
*/

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.