拦截器(interceptor)
特点:特点:双向拦截 request response
实现接口:Handlerinterceptor:
重写三个方法:
1.preHandle :处理器前实行方法:返回boolean值 默认:false, false结束 true继续执行
2.postHandle :处理器后执行的方法
3.afterCompletion :不管异常,渲染视图后执行的异常
执行流程
1.preHandle(前置方法)
2.返回false结束,true继续
3. Handle(处理器)
4.postHandle(后置方法)
5.afterCompletion(视图解析渲染)
多个拦截器
preHandle(1)
postHandle(1)
preHandle(1)
afterCompletion(2)
postHandle(2)
afterCompletion(2)
执行顺序(根据xml文件bean节点决定)
1.preHandle(1)
2.preHandle
3.Handle(处理器)
4.postHandle
5.postHandle(1)
6.Second afterCompletion
7.Second afterCompletion(1)