springmvc之HttpMessageConverter<T>接口

来源:互联网 发布:yy协议软件免费版 编辑:程序博客网 时间:2024/05/05 04:11

       

             spring从3.0开始提供一个HttpMessageConverter<T>接口,这个接口相当有用,spring可以针对Http报文头的ContentType来调用该类的默认实现类将HttpServletRequest转化成各种对象,如String,MultiValueMap,BufferedImage等类型,所以在做验证码或者上传文件时特别有用。spring默认加载该接口的四个默认实现类:StringHttpMessageConverter,ByteArrayHttpMessageConverter,SourceHttpMessageConverter,XmlAwareFormHttpMessageConverter.其余的例如处理json数据的默认类需要手动配置,具体配置例如:

            <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" p:messageConverters-ref="messageConverters"/>

           <util:list id="messageConverters">

                  <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" />

           </util:list>

          *这里用到了p命名空间,具体资料可以自己查阅

         

原创粉丝点击