Springmvc息转换器

当使用了<mvc:annotation-driven> 配置等同于@EnableWebMvc注解的时候就默认启用了响应消息转换器

1.原始字符串转换器:org.springframework.http.converter.StringHttpMessageConverter 
    输出 text/plan 原始字符串 
     默认ISO-8859-1编码  

2.文件下载流转换器:org.springframework.http.converter.ByteArrayHttpMessageConverter
   主要用于下载文件,输入文件流
   ContentType:application/octet-stream

3.资源转换器:org.springframework.http.converter.ResourceHttpMessageConverter
  默认读取所有类型的文件,如果可用的话将 ContentType:application/octet-stream 方式输出

4.表单数据转换器:org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
  主要用于读取 Form表单


5.xml转换读取器:org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter
  主要是处理xml数据  Content-type:application/*+xml

6.json转换器:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
  主要是处理json数据 Content-Type:application/json

可以在<mvc:annotation-driven> 中在加以明细配置
 

<mvc:annotation-driven>
        <mvc:message-converters>
            <!--解决@ResponseBody中文乱码-->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="defaultCharset" value="UTF-8"/>
            </bean>
            <!-- 输出json 默认 已经启用了 org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
                转换器设置我们可以自己修改 -->
            <!--<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="prettyPrint" value="false"/>
                <property name="objectMapper">
                    <bean class="xxxx.xxxx"></bean>
                </property>
            </bean>-->
        </mvc:message-converters>


    </mvc:annotation-driven>

猜你喜欢

转载自blog.csdn.net/QWERTY1994/article/details/93210545
今日推荐