Reprinted from https://www.cnblogs.com/fzj16888/p/5923348.html
method 1:
Block all URLs
<mvc:interceptors> <bean class="cn.ciss.interceptor.LoginInterceptor" /> </mvc:interceptors>
Method 2:
Blocking the specified URL
< mvc:interceptors > < mvc:interceptor > <!-- /** means all folders and subfolders inside /* is all folders, excluding subfolders / is the root directory of the web project-- > < mvc:mapping path ="/**" /> <!-- Addresses to be excluded from interception --> <!-- <mvc:exclude-mapping path="/userController/login"/> --> < bean id ="commonInterceptor" class ="cn.ciss.interceptor.LoginInterceptor" ></ bean > <!-- This class is our custom Interceptor --> </ mvc:interceptor > <!--When setting up multiple interceptors, first call the preHandle method in order, and then call the postHandle and afterCompletion methods of each interceptor in reverse order --> </ mvc:interceptors >
Method 3:
Precisely inject interceptors for a HandleMapping
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list> <bean class="cn.ciss.interceptor.LoginInterceptor"></bean> </list> </property> </bean>