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