Spring MVC学习笔记(七)
2019独角兽企业重金招聘Python工程师标准>>>
配置Spring MVC
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<mvc:annotation-driven />
</beans>
以上注册了一个RequestMappingHandlerMapping,一个RequestMappingHandlerAdapter和一个ExceptionHandlerExceptionResolver支持使用注解配置控制器方法。
自定义provided配置
<mvc:annotation-driven conversion-service="conversionService">
<mvc:message-converters>
<bean class="org.example.MyHttpMessageConverter"/>
<bean class="org.example.MyOtherHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBea
<property name="formatters">
<list>
<bean class="org.example.MyFormatter"/>
<bean class="org.example.MyOtherFormatter"/>
</list>
</property>
</bean>
配置拦截器
可以配置HandlerInterceptors或WebRequestIinterceptors应用与所有进来的请求或受限的具体URL。
使用<mvc:interceptors>元素
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
<mvc:interceptor>
<mapping path="/**"/>
<exclude-mapping path="/admin/**"/>
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
</mvc:interceptor>
<mvc:interceptor>
<mapping path="/secure/*"/>
<bean class="org.example.SecurityInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
这是定义一个ParameterizableViewController紧随转发到一个视图调用时的快捷方式。
配置视图控制器,使用<mvc:view-controller>元素
<mvc:view-controller path="/" view-name="home"/>
配置静态资源
<mvc:resources mapping="/resources/**" location="/public-resources/"/>
<mvc:resources mapping="/resources/**" location="/public-resources/" cacheperiod="31556926"/>
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/public-webresources/"/>
转载于:https://my.oschina.net/yaoliyc/blog/212821
Spring MVC学习笔记(七)相关推荐
- Spring MVC 学习笔记 对locale和theme的支持
Spring MVC 学习笔记 对locale和theme的支持 Locale Spring MVC缺省使用AcceptHeaderLocaleResolver来根据request header中的 ...
- Spring MVC 学习笔记一 HelloWorld
Spring MVC 学习笔记一 HelloWorld Spring MVC 的使用可以按照以下步骤进行(使用Eclipse): 加入JAR包 在web.xml中配置DispatcherServlet ...
- Spring MVC 学习笔记(整理)
SpringMVC学习 1.概述 Spring MVC是一种基于Java实现MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行解耦,基于请求-响应模型帮助我们 ...
- Spring MVC 学习笔记 json格式的输入和输出
Spring mvc处理json需要使用jackson的类库,因此为支持json格式的输入输出需要先修改pom.xml增加jackson包的引用 <!-- json --><depe ...
- Spring MVC学习笔记——SiteMesh的使用(转)
转自 SiteMesh的使用 SiteMesh的介绍就不多说了,主要是用来统一页面风格,减少重复编码的. 它定义了一个过滤器,然后把页面都加上统一的头部和底部. 需要先在WEB-INF/lib下引入s ...
- Spring MVC学习笔记
文章目录 创建一个servlet项目 导入依赖 添加Web框架 编写Servlet 注册这个servlet 编写跳转页面 配置Tomcat 第一个Spring MVC程序 1. web.xml的配置 ...
- 【Spring MVC学习笔记 六】SpringMVC框架整合AJAX完成局部刷新
本篇Blog介绍另一个常用的技术Ajax.虽然Ajax可以脱离SpringMVC去使用,但是SpringMVC对AJax有更好的支持 AJAX概念概述 AJAX即Asynchronous Javasc ...
- Spring MVC学习笔记——POJO和DispatcherServlet
POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. 使用POJO名称是为了避免和EJB(Enter ...
- Spring Boot学习笔记-基础(2)
Spring Boot学习笔记-基础(2) Spring Boot 优点: – 快速创建独立运行的Spring项目以及与主流框架集成 – 使用嵌入式的Servlet容器,应用无需打成WAR包 – st ...
最新文章
- USB无法识别原因分析及解决方案
- codeforces808G Anthem of Berland(kmp+自动机+dp)
- [探讨]route print PC与交换机的区别
- 二分图最小覆盖的Konig定理及其证明
- c#对象集合去重_C# List集合去重操作注意点
- ODS:输出多样化采样,有效增强白盒和黑盒攻击的性能 | NeurIPS 2020
- 计算机视觉如何给企业带来不同?
- pytorch 之 torch.max() 和 torch.min() 记录
- 使用单独的解决方案(类库)来开发DNN的模块-C#版本(2)
- 关于she'll脚本中echo -e使用sh命令执会显示参数-e-的问题
- Oracle Merge Into 的用法详解实例
- 视频剪辑软件到底哪个功能强?容易上手并且不要钱的?
- 郑州大学校园网使用指南
- 汇编学习 step by step
- AForge Video
- 【解决】jsPDF之长图片生成PDF(分页,失真)
- 机器学习基础随笔(3)
- 飞天系统和linux,用Linux或Windows系统运行抢茅台脚本在性能上有区别吗?
- 软件供应链安全——组件漏洞的治理
- HDMI Trans (FPGA)介绍及解析 (二)串并转换