SPring拦截器:
接口L"org.springframework.web.servlet.HandlerInterceptor"包含的方法:
1,public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception 普通 在某一个控制器的方法执行之前调用;
2,public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception 普通 正在执行的某一个E控制器的方法
3,public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception 普通 控制器的方法执行完毕后调用
applicationContext.xml文件中定义interceptors
<mvc:interceptors> <!-- 定义拦截器栈,可以定义有多个拦截器 -->
<mvc:interceptor> <!-- 定义某一个具体的拦截器 -->
<!-- 定义该拦截器使用的拦截器处理程序类,必须是HandlerInterceptor子类 -->
<bean class="cn.mldn.util.validate.ValidationInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
拦截器中最常使用的类:“org.springframework.web.method.HandlerMethod”
1,public Object getBean() 普通 返回触发次拦截器的程序类(XxxAction)
2,public Method getMethod() 普通 取得具体操作XxxAction中方法的Method对象
3,public Class<?> getBeanType() 普通 去得触发次拦截器程序类的class对象
4,public MethodParameter[] getMethodParameters 普通 取得所有提交到此方法上的参数
又有用户提交的参数,在拦截器里面都使用""org.springframework.core.MethodParameter""程序类进行接收;
1,public Method getMethod() 普通 取得调用的方法对象
2,public String getParameterName() 普通 取得提交到次Action上的参数名称
3,public Class<?> getParameterType() 普通 取得此参数的类型
Spring拦截器
最新推荐文章于 2021-03-28 19:12:51 发布