Spring MVC 3.1 之后如何配置messageConverters

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 @NumberFormat annotation through the ConversionService.

Support for formatting Date, Calendar, Long, and Joda Time fields using the @DateTimeFormat annotation.

Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is present on the classpath.

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.

MappingJackson2HttpMessageConverter (or MappingJacksonHttpMessageConverter) converts to/from JSON — added if Jackson 2 (or 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.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/923d5593a6dab76e4138ba6684fbe851.html