为了简化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的更多相关文章

  1. springmvc 配置之 mvc:default-servlet-handler

    配置dispatchServlet的方法一般是: <servlet> <servlet-name>mvc-servlet</servlet-name> <se ...

  2. 如何用Java类配置Spring MVC(不通过web.xml和XML方式)

    DispatcherServlet是Spring MVC的核心,按照传统方式, 需要把它配置到web.xml中. 我个人比较不喜欢XML配置方式, XML看起来太累, 冗长繁琐. 还好借助于Servl ...

  3. maven配置spring mvc+hibernate+spring框架

    作为一名刚出茅草屋的新手小白写的框架,仅适合新手小白借鉴,大神勿喷,谢谢...... 前天刚知道spring mvc这个框架现在也很流行,决定用它代替struts2来写我的毕业设计. ...作为一名新 ...

  4. springMVC 配置和使用

    springMVC相对于Struts2学习难度较为简单,并且更加灵活轻便. 第一步:导入jar包 spring.jar.spring-webmvc.jar.commons-logging.jar.sp ...

  5. springMvc配置xml使ResponseBody返回Json

    @ResponseBody 在返回的数据不是html标签的页面,而是其他某种格式的数据时(如json.xml等)使用: 不在springMvc中配置json的处理的话,我们通常会在Controller ...

  6. SpringMVC配置与使用

    一.MVC概要 MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范,用一种将业务逻辑.数据.显示分离的方法组织代码,MVC主要作用是降低了视图与业务 ...

  7. 基于java代码的springmvc配置

    在我的印象中,开发一个web项目首选当然是springmvc,而配置springmvc无非就是web.xml里配置其核心控制器DispatcherServlet.然后把所有的请求都交给它处理,再配个视 ...

  8. SpringMvc配置扫包之后,访问路径404问题解决

    场景: 1. 配置了Spring和SpringMvc, Spring管理非Controller类的Bean, SpringMvc管理涉及的Controller类 2. web.xml已经配置了Spri ...

  9. SpringMVC配置及使用

    SpringMVC基本配置 SpringMVC是基本请求响应模式的框架. 在项目中集成SpringMVC框架首先需要导入相关的jar包,所需包具体如下: commons-dbcp.jar common ...

随机推荐

  1. react中constructor()和super()的具体含义以及如何使用

    1.constructor()---super( )的基本含义 constructor()--构造方法 这是ES6对类的默认方法,通过new命令生成对象实例时自动调用该方法.并且,该方法是类中必须有的 ...

  2. xmoj142

    https://code.mi.com/problem/list/view?id=142 暴力. #include <bits/stdc++.h> using namespace std; ...

  3. 转载:[Java面经]干货整理, Java面试题(覆盖Java基础,Java高级,JavaEE,数据库,设计模式等)

    原文:http://www.cnblogs.com/wang-meng/p/5898837.html 一:继承.抽象类与接口区别.访问控制(private, public, protected,默认) ...

  4. linux学习:特殊符号,数学运算,图像与数组与部分终端命令用法整理

    指令:let.expr.array.convert.tput.date.read.md5.ln.apt.系统信息 一:特殊符号用法整理 系统变量 $# 是传给脚本的参数个数 $0 是脚本本身的名字 $ ...

  5. Nginx 自定义404、500、502 页面

    利用nginx的反向代理来实现 服务器404 和500 等状态码的自定义页面 1.nginx配置文件 nginx.conf 配置开启代理错误拦截 和配置页面  下划线部分  http { ...... ...

  6. mysql千万级数据量查询出所有重复的记录

    查询重复的字段需要创建索引,多个条件则创建组合索引,各个条件的索引都存在则不必须创建组合索引 有些情况直接使用GROUP BY HAVING则能直接解决:但是有些情况下查询缓慢,则需要使用下面其他的方 ...

  7. c#重命名文件,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”

    修改远程服务器的文件名,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”,“System.NotSupportedExcept ...

  8. 遍历二叉树 traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化

    遍历二叉树   traversing binary tree 线索二叉树 threaded binary tree 线索链表 线索化 1. 二叉树3个基本单元组成:根节点.左子树.右子树 以L.D.R ...

  9. mysql 数据库的数据类型

  10. delphi 中实现当期日期 减去 若干小时的方法

    假定当期日期为:2011-08-01 15:00:00 now - 1      :代表前一天的日期 返回值:2011-07-31 15:00:00 now - 1/3   :代表8小时前       ...