SpringMVC攔截器執行流程


1:MyInterceptor1、MyInterceptor2這2個攔截器都放行

MyInterceptor1......preHandle
MyInterceptor2......preHandle

MyInterceptor2......postHandle
MyInterceptor1......postHandle

MyInterceptor2......afterCompletion
MyInterceptor1......afterCompletion

preHandle執行順序和攔截器放置順序一致;postHandle、afterCompletion執行順序和攔截器放置順序相反


2:MyInterceptor1放行、MyInterceptor2不放行

MyInterceptor1......preHandle
MyInterceptor2......preHandle
MyInterceptor1......afterCompletion

MyInterceptor2不放行,MyInterceptor2的postHandle、afterCompletion方法不會執行
只要有一個攔截器不放行,postHandle方法不會執行


3:MyInterceptor1、MyInterceptor2這2個攔截器都不放行

MyInterceptor1......preHandle

MyInterceptor1不放行,MyInterceptor1的postHandle、afterCompletion方法不會執行
MyInterceptor1不放行,MyInterceptor2不會執行


若系統中有統一日志記錄處理,應該將日志處理的攔截器放在第一個位置,並且必須放行,這樣才能保證afterCompletion方法會執行
(若其它攔截器不放行,會導致postHandle方法不執行)

若系統中有登錄校驗攔截器、權限校驗攔截器
應該把登錄校驗攔截器放在權限校驗攔截器的前面,因為只有登錄通過了,才會進行權限校驗


單個攔截器執行流程:


不放行
preHandle------>返回


放行
preHandle------>handler中方法------>postHandle------>handler中方法返回ModelAndView------>afterCompletion


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM