springmvc 拦截器
拦截器类 ==> 三个方法
方法前
方法后
页面渲染后
如何使用拦截器?
1)在springmvc.xml中配置拦截器
<!--springmvc 拦截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <!-- 自定义的拦截器类 --> <bean class="com.itheima.springmvc.interceptor.Interceptor1"> </bean> </mvc:interceptor> </mvc:interceptors>
2)自定义拦截器,写处理逻辑
public class Interceptor1 implements HandlerInterceptor{ @Override public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception { System.out.println("方法1前"); return true; } @Override public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { // TODO Auto-generated method stub System.out.println("方法1后"); } @Override public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { System.out.println("页面1渲染完毕后"); } }
3) 访问请求 查看结果
相关推荐
zhangdy0 2020-05-31
HappyHeng 2020-05-16
whbing 2020-04-11
MicroBoy 2020-01-23
HappyHeng 2020-05-28
横云断岭 2020-01-04
Julywhj 2019-12-14
方志朋 2019-12-08
方志朋 2019-12-03
neweastsun 2019-11-11
whbing 2019-10-21
ScarletLina 2016-05-03
JINKAI 2019-03-27
zhongjcbill 2019-03-27
lihaoxiang 2018-07-23
mendeliangyang 2019-06-27
luojinbai 2017-02-27