springmvc配置之mvc:annotation-driven
为了简化springmvc配置,spring同时引入了mvc namespace, 配置了
<mvc:annotation-driven/>
spring会默认注册a RequestMappingHandlerMapping, a RequestMappingHandlerAdapter, and an ExceptionHandlerExceptionResolver 三个bean, 来支持使用注解(@RequestMapping、@ExceptionHandler、@Controller等)修饰的controller处理请求。同时还有以下一些特性:
1、 Spring 3 style type conversion through a ConversionService instance in addition to the JavaBeans PropertyEditors used for Data Binding.
2、 Support for formatting Number fields using the @NumberFormat annotation through the ConversionService.
3、 Support for formatting Date, Calendar, Long, and Joda-Time fields using the @DateTimeFormat annotation.
4、 Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is present on the classpath.
5、 HttpMessageConverter support for @RequestBody method parameters and @ResponseBody method return values from @RequestMapping or @ExceptionHandler methods.This is the complete list of HttpMessageConverters set up by mvc:annotation-driven:
a. ByteArrayHttpMessageConverter converts byte arrays.
b. StringHttpMessageConverter converts strings.
c. ResourceHttpMessageConverter converts to/from org.springframework.core.io.Resource for all media types.
d. SourceHttpMessageConverter converts to/from a javax.xml.transform.Source.
e. FormHttpMessageConverter converts form data to/from a MultiValueMap<String, String>.
f. Jaxb2RootElementHttpMessageConverter converts Java objects to/from XML — added if JAXB2 is present and Jackson 2 XML extension is not present on the classpath.
g. MappingJackson2HttpMessageConverter converts to/from JSON — added if Jackson 2 is present on the classpath.
h. MappingJackson2XmlHttpMessageConverter converts to/from XML — added if Jackson 2 XML extension is present on the classpath.
i. AtomFeedHttpMessageConverter converts Atom feeds — added if Rome is present on the classpath.
j. RssChannelHttpMessageConverter converts RSS feeds — added if Rome is present on the classpath.
配置示例:
<bean name="fastJson" class="com.alibaba.fastjson.support.config.FastJsonConfig">
<property name="features">
<list>
<value>AllowSingleQuotes</value>
</list>
</property>
<property name="serializerFeatures">
<list>
<value>QuoteFieldNames</value>
<value>WriteEnumUsingToString</value>
<value>WriteEnumUsingName</value>
<value>WriteNullNumberAsZero</value>
<value>SkipTransientField</value>
<value>WriteDateUseDateFormat</value>
</list>
</property>
</bean>
<!--默认的mvc注解映射的支持 -->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
<value>text/json;charset=UTF-8</value>
</list>
</property>
<property name="fastJsonConfig" ref="fastJson"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
引用:
1、 springdoc
2、what's annotation-driven do
springmvc配置之mvc:annotation-driven的更多相关文章
- springmvc 配置之 mvc:default-servlet-handler
配置dispatchServlet的方法一般是: <servlet> <servlet-name>mvc-servlet</servlet-name> <se ...
- 如何用Java类配置Spring MVC(不通过web.xml和XML方式)
DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...
- maven配置spring mvc+hibernate+spring框架
作为一名刚出茅草屋的新手小白写的框架,仅适合新手小白借鉴,大神勿喷,谢谢...... 前天刚知道spring mvc这个框架现在也很流行,决定用它代替struts2来写我的毕业设计. ...作为一名新 ...
- springMVC 配置和使用
springMVC相对于Struts2学习难度较为简单,并且更加灵活轻便. 第一步:导入jar包 spring.jar.spring-webmvc.jar.commons-logging.jar.sp ...
- springMvc配置xml使ResponseBody返回Json
@ResponseBody 在返回的数据不是html标签的页面,而是其他某种格式的数据时(如json.xml等)使用: 不在springMvc中配置json的处理的话,我们通常会在Controller ...
- SpringMVC配置与使用
一.MVC概要 MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范,用一种将业务逻辑.数据.显示分离的方法组织代码,MVC主要作用是降低了视图与业务 ...
- 基于java代码的springmvc配置
在我的印象中,开发一个web项目首选当然是springmvc,而配置springmvc无非就是web.xml里配置其核心控制器DispatcherServlet.然后把所有的请求都交给它处理,再配个视 ...
- SpringMvc配置扫包之后,访问路径404问题解决
场景: 1. 配置了Spring和SpringMvc, Spring管理非Controller类的Bean, SpringMvc管理涉及的Controller类 2. web.xml已经配置了Spri ...
- SpringMVC配置及使用
SpringMVC基本配置 SpringMVC是基本请求响应模式的框架. 在项目中集成SpringMVC框架首先需要导入相关的jar包,所需包具体如下: commons-dbcp.jar common ...
随机推荐
- Web版记账本开发记录(二)开发过程遇到的问题小结1 对数据库的区间查询
问题1 对数据库的区间查询 如功能显示,想要按照年份和月份查询相应的记录,就要使用区间查询 对应的代码如下 servlet层的ChaXun java.sql.Date sDate = new java ...
- 转:浅谈SimpleDateFormat的线程安全问题
转自:https://blog.csdn.net/weixin_38810239/article/details/79941964 在实际项目中,我们经常需要将日期在String和Date之间做转化, ...
- rest_framework 跨域和CORS
跨域和CORS 本节目录 一 跨域 二 CORS 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 跨域 同源策略(Same origin policy)是一种约定, ...
- bbs论坛流程
1.发表帖子时候操作 数据库: board+板块号 :readertopicsX中插入数据 boardtmp(临时表插入审核数据) countandmax(记录每个板块最大主贴ID) 一. Redis ...
- wrapper induction随笔
本文是一篇介绍Wrapper Induction的阅读笔记,原文详见<Wrapper induction:Efficiency and expressiveness>. Wrapper I ...
- 转载:Android RecyclerView 使用完全解析 体验艺术般的控件
转自:https://blog.csdn.net/lmj623565791/article/details/45059587
- python练习题-day19
1.将字符串的时间"2017-10-10 23:40:00"转换为时间戳和时间元组 import time s="2017-10-10 23:40:00" st ...
- Appium IOS 使用多模拟器并发执行测试
申明一下 转载请注明出处 复制粘贴请滚蛋 !!!!!!!! 最近在是用appium进行app的并发测试,并且Android已经实现在同一台PC机使用多个模拟器并发测试的功能 这里说一句模拟器使 ...
- MySQL数据库常用命令和概念 (1)
一.数据库的创建: 1.创建一个名称为mydb1的数据库 create database mydb1; 2.创建一个使用utf8字符集的mydb2数据库. create database mydb2 ...
- 使用Apache JMeter对SQL Server、Mysql、Oracle压力测试(一)
前段时间面试被问到了数据库方面的知识:比如选择什么样的数据库,如何优化,怎么加索引,于是想到了自己动手测试一下常用数据库的性能: 第一步,下载好JMeter之后打开运行.话说这个JMeter打开还真是 ...