使用spring mvc时,我们会在配置文件里添加<mvc:annotation-driven /><beans>
这个配置文件都加载了那些类呢?
1. Among others, registers:
* RequestMappingHandlerMapping
* RequestMappingHandlerAdapter
* ExceptionHandlerExceptionResolver
in support of processing requests with annotated controller methods using annotations such as @RequestMapping , @ExceptionHandler, etc.
2. Enables Spring 3 style type conversion through a ConversionService instance in addition to the JavaBeans PropertyEditors used for Data Binding.
3. Enables support for formatting Number fields using the @NumberFormat annotation through the ConversionService.
4. Enables support for formatting Date, Calendar, Long, and Joda Time fields using the @DateTimeFormat annotation, if Joda Time 1.3 or higher is present on the classpath.
5. Enables support for validating @Controller inputs with @Valid, if a JSR-303 Provider is present on the classpath.
6. Enables 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:
* ByteArrayHttpMessageConverter converts byte arrays.
* StringHttpMessageConverter converts strings.
* ResourceHttpMessageConverter converts to/from org.springframework.core.io.Resource for all media types.
* SourceHttpMessageConverter converts to/from a javax.xml.transform.Source.
* FormHttpMessageConverter converts form data to/from a MultiValueMap<String, String>.
* Jaxb2RootElementHttpMessageConverter converts Java objects to/from XML — added if JAXB2 is present on the classpath. This converter can read classes annotated with XmlRootElement and XmlType, and write classes annotated with withXmlRootElement, or subclasses thereof.
* MappingJacksonHttpMessageConverter converts to/from JSON — added if Jackson is present on the classpath.
* AtomFeedHttpMessageConverter converts Atom feeds — added if Rome is present on the classpath.
* RssChannelHttpMessageConverter converts RSS feeds — added if Rome is present on the classpath.
类似controller中ajax请求直接返回对象被组装成json格式,就是由于该配置文件注册了MappingJacksonHttpMessageConverter对象,当我们的工程引入了jackson相关的jar包,spring就可以自动将我们的返回对象封装成json对象输出给客户端。
分享到:
相关推荐
NULL 博文链接:https://yihuawuye1.iteye.com/blog/2105063
Spring MVC 教程 快速入门 深入分析 目录 一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc DispatcherServlet说明 ...十九、 <mvc:annotation-driven /> 到底做了什么工作
个人认为相当适合入门和知识巩固!! 一、前言 二、spring mvc 核心类与接口 ...十九、 <mvc:annotation-driven /> 到底做了什么工作 二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址
一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 四、spring mvc ...十九、 <mvc:annotation-driven /> 到底做了什么工作 二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址
Spring MVC internationalization annotation example 这个是annotation 方式的国际化 访问http://localhost:8080/login.htm
主要介绍了Spring MVC Annotation验证的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
利用Spring mvc annotation写成的demo
Spring MVC 整合Hibernate的一个小小的用例,适合初学Spring MVC 的学者。
SpringMVC: 一、前言 二、spring mvc 核心类与接口 三、spring mvc 核心流程图 ...十九、 <mvc:annotation-driven /> 到底做了什么工作 二十、 本文中springMVC.xml配置文件是核心,这里给一个下载地址
一个简单的spring mvc登录案例,采用的是annotation方式。
基于注解的Spring MVC,环境搭建,示例代码
Spring mvc Aop+annotation实现系统日志记录功能实现的jar包asm-3.3.jar ,aspectjrt.jar , aspectjweaver.jar , cglib-nodep-2.1_3.jar , spring-aop.jar
一个简单的例子,SPringMVC最常用的开发模式,通过注解的方式配置一个控制器和请求!
这里提供了Spring3 MVC中较为常见的使用方法,主要是利用Spring3官方文档建议使用的Annotation进行开发的一般步骤,包含了常见的集中Annotation的使用方法。
<mvc:annotation-driven> </mvc:annotation-driven> 中配置Json格式乱码。代码如下: <!--json格式乱码处理--> <mvc:message-converters register-defaults="true"> <bean class="org.springframework....
Chapter 6- Annotation-driven development with Spring Chapter 7 - Database interaction using Spring Chapter 8 - Messaging, emailing, asynchronous method execution, and caching using Spring Chapter 9 - ...
Annotation-driven development with Spring Integrating portlets with databases PART 3 ADVANCED PORTLET DEVELOPMENT Personalizing portlets Communicating with other portlets Ajaxing portlets Reusable ...
51. <tx:annotation-driven transaction-manager="transactionManager" /> 52. <tx:annotation-driven mode="aspectj"/> 53. 54. <aop:aspectj-autoproxy/> 55.</beans> hibernate.properties数据库连接...
spring-mvc.xml 配置自动扫描的包、配置视图解析器 如何把 handler方法返回值解析为实际的物理视图、配置静态资源映射静态资源交给默认的Servlet、配置 mvc:annotation-driven标签开启注解(4)@RestController =@...
将dwr集成到spring mvc(dwr的配置是基于xml)