spring mvc 拦截器配置
来源:互联网 发布:细川忠兴 知乎 编辑:程序博客网 时间:2024/05/16 01:28
以前将filter和servlet都配置在web.xml中,有了spring mvc后,可以讲servlet配置为controller,将interceptor在spring mvc配置文件中xxx-servlet.xml中。
<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/user/detail.json"/> <mvc:mapping path="/user/update.json"/> <mvc:mapping path="/user/list.json"/> <bean class="com.qunar.homework.web.interceptor.LoginInterceptor"/> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/user/*"/> <bean class="com.qunar.homework.web.interceptor.RequestTimeInterceptor"/> </mvc:interceptor> </mvc:interceptors>
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:resources mapping="/resources/**" location="/resources/" /> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/user/detail.json"/> <mvc:mapping path="/user/update.json"/> <mvc:mapping path="/user/list.json"/> <bean class="com.qunar.homework.web.interceptor.LoginInterceptor"/> </mvc:interceptor> <mvc:interceptor> <mvc:mapping path="/user/*"/> <bean class="com.qunar.homework.web.interceptor.RequestTimeInterceptor"/> </mvc:interceptor> </mvc:interceptors> <!--启用 Spring 的注解 load 方式--> <context:annotation-config /> <!--将所有的 controller 作为 Bean 注册到Spring的应用上下文中--> <context:component-scan base-package="qunar.web.spring, com.qunar.homework.web.controller" /> <!--<mvc:annotation-driven />--> <!--这里通过扫描 qunar.web.spring 包下面的 WebConfig,启用 @JsonBody注解--> <!--如果使用 @JsonBody,注意一下--> <!--1. 不能使用短标签 mvc:annotation-driven--> <!--2. 不需要自己注册 HandlerAdapter--> <!-- 添加视图解析器,并为逻辑视图加上前缀和后缀,查找视图模板,生成最终的解析视图 xxx.jsp--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1" /> </bean> <!--<!– 注册HandlerMapping,这里包含了所有url到controller的映射关系 –>--> <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">--> <!--<property name="interceptors">--> <!--<list>--> <!--<bean class="com.qunar.homework.web.interceptor.RequestTimeInterceptor" />--> <!--</list>--> <!--</property>--> <!--</bean>--> <mvc:default-servlet-handler /></beans>
0 0
- spring mvc 拦截器配置
- spring mvc 拦截器配置
- Spring MVC拦截器的配置
- Spring mvc拦截器的配置
- spring mvc xml配置拦截器
- Spring mvc interceptor配置拦截器
- Spring mvc 拦截器 配置详解
- Spring mvc 拦截器 配置心得
- Spring mvc interceptor配置拦截器
- Spring mvc interceptor配置拦截器
- SPRING MVC interceptor配置拦截器
- Spring mvc 拦截器 interceptor 配置
- Spring mvc interceptor配置拦截器
- Spring mvc interceptor配置拦截器
- Spring MVC系列(二):拦截器配置
- Spring MVC拦截器配置实例
- Spring MVC配置自定义拦截器
- Spring MVC拦截器,登录拦截简单配置
- SQL Server set nocount on 与JDBC: The statement did not return a result
- 安装svn出现subversion requires zlib
- 阿里云(三)
- 决定你是富人还是穷人的12条
- Longest Consecutive Sequence 最长连续子序列
- spring mvc 拦截器配置
- RAII的一些实现
- Java多线程编程总结
- unable to load default svn client 和 Eclipse SVN 插件与TortoiseSVN对应关系
- 线性表的链式表示和实现
- [Leetcode] Sum Root to Leaf Numbers
- 在eclipse中设计BPMN 2.0工作流定义的基本步骤
- 生个女儿蘑菇高仿机废话价格等级吗
- 【索引】Maths - Number Theory