拦截器是Spring中的一个概念。
1.XML配置方式
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<mvc:exclude-mapping path="/testRequestEntity"/>
<!-- <bean id="myInterceptor" class="xxx"></bean>-->
<ref bean="firstInterceptor"></ref>
</mvc:interceptor>
</mvc:interceptors>
2.拦截器编写
//如果通过xml配置也可以
@Component
public class FirstInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.err.println("FirstInterceptor的preHandler");
return false;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
System.err.println("First-Posthandle");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
System.err.println("First-afterCompletion");
}
}
3.执行顺序