美文网首页
SpringMVC拦截器

SpringMVC拦截器

作者: 高尧仨 | 来源:发表于2020-04-08 16:53 被阅读0次

SpringMVC拦截器;全局拦截和局部拦截

在拦截类中实现HandlerInterceptor,中3个抽象方法

在springMVC配置中注册拦截器

查看是否存在:::xmlns:mvc="http://www.springframework.org/schema/mvc"空间和  ::http://www.springframework.org/schema/mvc 
   和:::http://www.springframwork.org/schema/mvc/spring-mvc-3.0.xsd

<!注册拦截器>

  <mvc:interceptors><bean class="对应的拦截器方法类,全类拦截">  <mvc:mapping path="/viewAll.form"/拦截方法中以viewall.form结尾的注释,在java类中添加@RequestMapping("/viewAll")></mvc:interceptors>

实现拦截器2个方法

  1;  HandlerInterceptor 中preHandle方法有返回值return true执行其余俩个方法,return flase 关闭

     2;WebRequestInterceptor接口来编写向SpringMVC框架的写法不变,弊端:preHandle方法没有返回值。

使用场景;1解决乱码(直接在方法里添加UTF-8);2;解决登陆权限问题

拦截器和过滤器区别;

  过滤器Filter依赖于Servle容器,基于回调函数,过滤范围大                       拦截器Interceprtor依赖于框架容器,基于反射机制,只过滤请求

相关文章

网友评论

      本文标题:SpringMVC拦截器

      本文链接:https://www.haomeiwen.com/subject/puhvvttx.html