首页 > 代码库 > SpringMVC 拦截器

SpringMVC 拦截器

public class LoginIntercetor implements HandlerInterceptor{    @Override    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {        System.out.println("进入拦截器");        return true;    }    @Override    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {        System.out.println("postHandler");    }    @Override    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {        System.out.println("处理完成");    }}

  

    <!--配置拦截器-->    <mvc:interceptors>        <mvc:interceptor>            <mvc:mapping path="/**"/>            <bean class="com.core.LoginIntercetor"/>            <!--那些类不进入拦截器-->            <!--<mvc:exclude-mapping path=""></mvc:exclude-mapping>-->        </mvc:interceptor>        <mvc:interceptor>            <mvc:mapping path="/**"/>            <bean class="com.core.LoginIntercetor"/>        </mvc:interceptor>    </mvc:interceptors>

  

SpringMVC 拦截器