package com.hzlssd.company.interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; public class SomeInterceptor implements HandlerInterceptor{ @Override public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { System.out.println("請求處理完成后調(diào)用"); } @Override public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { System.out.println("處理器執(zhí)行后調(diào)用"); } @Override public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception { System.out.println("處理器執(zhí)行前調(diào)用"); return true; } } SpringMVC攔截器 <!-- 攔截器 配置--> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/login/*"/> <mvc:exclude-mapping path="/admin/*"/> <bean class="com.hzlssd.company.interceptor.SomeInterceptor"/> </mvc:interceptor> <!-- 多個攔截器配置使用 --> <!-- <mvc:interceptor> <mvc:mapping path="/**"/> <mvc:exclude-mapping path="/login/*"/> <bean class="com.hzlssd.company.interceptor.LoginInterceptor"/> </mvc:interceptor> --> </mvc:interceptors> |
|
來自: 擎天豬mpnlajkd > 《Spring》