spring mvc <mvc:annotation-driver/>详解
2016-06-12 18:39
585 查看
To enable MVC Java config add the annotation
one of your
To achieve the same in XML use the
in your DispatcherServlet context (or in your root context if you have no DispatcherServlet context defined):
The above registers a
a
and an
others) in support of processing requests with annotated controller methods using annotations such as
and others.
It also enables the following:
Spring 3 style type conversion through a ConversionService instance
in addition to the JavaBeans PropertyEditors used for Data Binding.
Support for formatting Number
fields using the
through the
Support for formatting
and Joda Time fields using the
Support for validating
with
if a JSR-303 Provider is present on the classpath.
for
parameters and
return values from
This is the complete list of HttpMessageConverters set up by mvc:annotation-driven:
byte arrays.
strings.
to/from
all media types.
to/from a
form data to/from a
Java objects to/from XML — added if JAXB2 is present and Jackson 2 XML extension is not present on the classpath.
to/from JSON — added if Jackson 2 is present on the classpath.
to/from XML — added if Jackson 2 XML extension is present on the classpath.
Atom feeds — added if Rome is present on the classpath.
RSS feeds — added if Rome is present on the classpath.
See Section 22.16.12,
“Message Converters” for more information about how to customize these default converters.
@EnableWebMvcto
one of your
@Configurationclasses:
@Configuration @EnableWebMvc public class WebConfig { }
To achieve the same in XML use the
mvc:annotation-drivenelement
in your DispatcherServlet context (or in your root context if you have no DispatcherServlet context defined):
<?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>
The above registers a
RequestMappingHandlerMapping,
a
RequestMappingHandlerAdapter,
and an
ExceptionHandlerExceptionResolver(among
others) in support of processing requests with annotated controller methods using annotations such as
@RequestMapping,
@ExceptionHandler,
and others.
It also enables the following:
Spring 3 style type conversion through a ConversionService instance
in addition to the JavaBeans PropertyEditors used for Data Binding.
Support for formatting Number
fields using the
@NumberFormatannotation
through the
ConversionService.
Support for formatting
Date,
Calendar,
Long,
and Joda Time fields using the
@DateTimeFormatannotation.
Support for validating
@Controllerinputs
with
@Valid,
if a JSR-303 Provider is present on the classpath.
HttpMessageConvertersupport
for
@RequestBodymethod
parameters and
@ResponseBodymethod
return values from
@RequestMappingor
@ExceptionHandlermethods.
This is the complete list of HttpMessageConverters set up by mvc:annotation-driven:
ByteArrayHttpMessageConverterconverts
byte arrays.
StringHttpMessageConverterconverts
strings.
ResourceHttpMessageConverterconverts
to/from
org.springframework.core.io.Resourcefor
all media types.
SourceHttpMessageConverterconverts
to/from a
javax.xml.transform.Source.
FormHttpMessageConverterconverts
form data to/from a
MultiValueMap<String, String>.
Jaxb2RootElementHttpMessageConverterconverts
Java objects to/from XML — added if JAXB2 is present and Jackson 2 XML extension is not present on the classpath.
MappingJackson2HttpMessageConverterconverts
to/from JSON — added if Jackson 2 is present on the classpath.
MappingJackson2XmlHttpMessageConverterconverts
to/from XML — added if Jackson 2 XML extension is present on the classpath.
AtomFeedHttpMessageConverterconverts
Atom feeds — added if Rome is present on the classpath.
RssChannelHttpMessageConverterconverts
RSS feeds — added if Rome is present on the classpath.
See Section 22.16.12,
“Message Converters” for more information about how to customize these default converters.
Jackson JSON and XML converters are created using ObjectMapperinstances created by Jackson2ObjectMapperBuilderin order to provide a better default configuration. This builder customizes Jackson’s default properties with the following ones: DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESis disabled. MapperFeature.DEFAULT_VIEW_INCLUSIONis disabled. It also automatically registers the following well-known modules if they are detected on the classpath: jackson-datatype-jdk7: support for Java 7 types like java.nio.file.Path. jackson-datatype-joda: support for Joda-Time types. jackson-datatype-jsr310: support for Java 8 Date & Time API types. jackson-datatype-jdk8: support for other Java 8 types like Optional. |
相关文章推荐
- java 深度复制与浅度复制的研究
- 黑马程序员——Java基础---eclipse和API
- Java8-Stream使用实战
- 【初探Spring】——Spring IOC(二):初始化过程—简介
- Spring Boot 实践折腾记(三):三板斧,Spring Boot下使用Mybatis
- 纯干货,Spring-data-jpa详解,全方位介绍
- struts实现文件上传下载
- Struts2配置拦截器的后缀名
- mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.String'(转)
- Java时间为什么从1970-01-01 00:00:00 000开始
- spring mvc @ResponseBody返回中文乱码解决
- eclipse jni报错:UnsatisfiedLinkError: no *** in java.library.path
- struts action接收参数的三种方法
- Java调用本地接口:java.lang.UnsatisfiedLinkError
- spring整合数据源
- 学JavaWeb一年,小谈一些基础知识的理解
- 通过注解在方法级别上使用拦截器做登录权限校验
- Spring Security 简介
- Spring Data JPA初使用
- 从ArrayList看Java泛型