为了简化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. CentOS下的Mysql的安装和使用

    1.使用安装命令 :yum -y install mysql mysql-server mysql-devel 安装完成却发现Myserver安装缺失,在网上找原因,原来是因为CentOS 7上把My ...

  2. 关于DTO的理解

    转自大神loveis715博文:http://www.cnblogs.com/loveis715/p/4379656.html 在一个web服务的实现中,我们常常需要访问数据库,并将从数据库中取得的数 ...

  3. MyISAM和Innodb区别,为什么?

    事务支持 MyISAM不支持事务,而InnoDB支持. InnoDB的AUTOCOMMIT默认是打开的,即每条SQL语句会默认被封装成一个事务,自动提交,这样会影响速度, 所以最好是把多条SQL语句显 ...

  4. [LeetCode] K-th Symbol in Grammar 语法中的第K个符号

    On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace ...

  5. ubuntu重复登录问题

    第一次遇到: 昨天好不容易装好了驱动,紧接着装了CUDA,cuDNN,Anaconda,VSCode等等.然后安装pytorch的时候遇到了下载的问题,后来也算搞定了.但是在更换了显示器后重启(好像是 ...

  6. P1316 丢瓶盖--(二分答案)

    题目描述 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想从这些瓶盖里找出B个,使得距离最近的2个距离最大,他想知道,最大可以到多少呢? 输入输出 ...

  7. char

    1 char是多少位的 2 java用的是什么方式表示字符 3 Unicode是用多少位表示的 1的答案是16位的,2的答案是Unicode,3的答案是16位 值得注意的是,2的答案并不是utf-8 ...

  8. pta编程总结

    币值转换 (20 分) 输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式.如23108元,转换后变成“贰万叁仟壹百零捌”元.为了简化输出,用小写英文字母a-j ...

  9. Math工具类

    public static void main(String[] args) { // 工具类,所有方法都以静态方法提供,没有实例存在的意义 // 不提供任何实例的方法,代表当前类属于无状态的. // ...

  10. day23:类的命名空间和组合

    1,类属性:静态属性,方法:动态属性:双下init方法,每当我们调用类的时候就会自动的触发这个方法,默认传self,在init方法里面可以对self赋值:在类的内部,self就是一个对象,我们自己实例 ...