博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring mvc annotation-driven
阅读量:6268 次
发布时间:2019-06-22

本文共 2269 字,大约阅读时间需要 7 分钟。

hot3.png

使用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
. * 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对象输出给客户端。

转载于:https://my.oschina.net/dreamnight/blog/695058

你可能感兴趣的文章
Mybatis通用Mapper
查看>>
文件磁盘命令(就该这么学6章内容)
查看>>
2016-207-19 随笔
查看>>
java的double类型如何精确到一位小数?
查看>>
看看国外的javascript题目,你能全部做对吗?
查看>>
ffmpeg 如何选择具有相同AVCodecID的编解码器 (AVCodec)
查看>>
真正解决 Windows 中 Chromium “缺少 Google API 密钥” 的问题
查看>>
Spring 之 AOP
查看>>
软件项目管理|期末复习(二)
查看>>
直接调用VS.net2005中的配置界面
查看>>
程序员的自我修养五Windows PE/COFF
查看>>
关于字符集,编码格式,大小端的简单总结
查看>>
js string 转 int Number()
查看>>
课堂练习:ex 4-20
查看>>
20155328 2016-2017-2 《Java程序设计》 第8周学习总结
查看>>
python操作redis--string
查看>>
echarts图表初始大小问题及echarts随窗口变化自适应
查看>>
Inherits、CodeFile、CodeBehind的区别
查看>>
创建一个SimpleDlg
查看>>
使用XML生成菜单
查看>>