2023-09-16
springmvc.xml
<!--配置拦截器--> <mvc:interceptors> <mvc:interceptor> <!--配置需要拦截的请求的请求路径--> <mvc:mapping path="/**"/> <!--配置需要排除拦截的请求的请求路径--> <mvc:exclude-mapping path="/abc"/> <!--配置拦截器--> <ref bean="firstInterceptor"/> </mvc:interceptor> </mvc:interceptors>
FirstInterceptor
package com.hh.interceptor; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author hh * @version 1.0 * @DATE 2023-09-16 10:35:31 */ @Component public class FirstInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("preHandle"); return true; } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { System.out.println("postHandle"); } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { System.out.println("afterCompletion = "); } }
标签:HttpServletRequest,Exception,拦截器,springmvc,配置,HttpServletResponse,springframewor From: https://www.cnblogs.com/isDaHua/p/17706455.html