Learning Blog: http://elf8848.iteye.com/blog/875830/
Version used in my project: 4.2.0. Blog time earlier, 11, learning is Spring3 MVC. I do not know if there is any change in the version of the larger features.
Spring MVC Tutorial (iii) interceptors
Interceptors in 1.Spring
(1) Interceptor interface
Spring provides an interceptor interface. Implement this interface or inherit this class, you can implement your own interceptor.
Org.springframework.web.servlet. handlerinterceptor interface 2 Org.springframework.web.servlet.handler. Handlerinterceptoradapter Adapter
Implements handlerinterceptor// slightly
Handlerinteceptor has 3 methods: preprocessing, post-processing (call service and return Modelandview, but no page rendering), return processing (page already rendered).
The object handler in the parameter is the next interceptor.
1//Action before executing2PublicBooleanPrehandle(HttpServletRequest request,httpservletresponse response, Object handler);34 // perform 5 public void posthandle (httpservletrequest Request,httpservletresponse response, Object handler, Modelandview Modelandview); 6 7 // Last execution, can be used to release resources 8 public void aftercompletion ( HttpServletRequest request,httpservletresponse response, object Handler , Exception ex)
(2) The execution process of the Interceptor
2017.3.31 Spring MVC Tutorial (iii) Request mapping (static file access, interceptors)