SpringMVC registration interceptor

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

copy code
    < 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 >
copy code

Method 3:

  Precisely inject interceptors for a HandleMapping

copy code
<bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <list>
                <bean class="cn.ciss.interceptor.LoginInterceptor"></bean>
            </list>
        </property>
    </bean>
copy code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326051982&siteId=291194637