filter; Spring Interceptor Slicing summary

Source: Internet
Author: User

1. Springmvc Interceptor
implement the Handlerinterceptor interface as follows: Public classHandlerInterceptor1 implements Handlerinterceptor {//This method is called after the controller executes and the view returns//This is where you get exception information when the controller is executed.//The operation log can be recorded here@Override Public void aftercompletion(httpservletrequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) t Hrows Exception {System. out. println ("handlerinterceptor1....aftercompletion"); }    //This method is called after the controller executes but does not return a view//The model data can be processed before returning to the user, for example, by adding common information to the page display@Override Public void posthandle (httpservletrequest arg0, HttpServletResponse arg1, Object arg2, Modelandview arg3) thr oWS Exception {System. out. println ("Handlerinterceptor1....posthandle"); }    //This method is called before the controller executes//returns true to continue execution, returning false to abort execution//This can include login check, permission interception, etc.@Override Publicboolean prehandle(httpservletrequest arg0, HttpServletResponse arg1, Object handler) throws Exception { System. out. println ("Handlerinterceptor1....prehandle"); Handlermethod Handlermethod = (Handlermethod) Handler;   ///The class name HandlerMethod.getBean.getClass () can be intercepted by the Interceptor . GetName ();
Get Method Name
  Handlermethod. GetMethod (). GetName (); // set to True, test using return true ; }}2. Interceptor Configurationconfiguring interceptors in Springmvc.xml<!--configuring interceptors--><mvc:interceptors> <mvc:interceptor> <!--all requests go to the interceptor--<mvc:m Apping path="/**"/> <!--Configure specific interceptors--<beanclass="Com.shan.interceptor.HandlerInterceptor1"/> </mvc:interceptor> <mvc:interceptor> <!--all requests go to the interceptor--<mvc:mapping path ="/**"/> <!--Configure specific interceptors--<beanclass="Cn.sea.interceptor.HandlerInterceptor2"/> </mvc:interceptor></mvc:interceptors>

3. Use interceptors to detect the execution time of each method

4 Filter implementation time-consuming

5. Time-consuming use of slices

filter; Spring Interceptor Slicing summary

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.