当前位置 : 主页 > 编程语言 > c++ >

SpringMVC拦截器

来源:互联网 收集:自由互联 发布时间:2021-07-03
拦截器 ---------拦截器package org.tlgg.interceptor;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.HandlerInterceptor;import org.springframework.web.ser
拦截器
---------拦截器
package org.tlgg.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 MyInterceptor implements HandlerInterceptor{

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("最后执行,通常用于释放资源");
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		System.out.println("在controller处理完,生成视图之前");
		
	}

	@Override
	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
		System.out.println("在请求controller之前,return true表示放行,false表示拦截");
		return true;
	}

}
-------spring.xml配置

 
	
网友评论