欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

json转换器映射文件配置

程序员文章站 2022-05-19 15:37:56
...
//MappingJacksonHttpMessageConverter转换器,将对象转为json响应给浏览器 :

 1 <mvc:annotation-driven>
 2         <mvc:message-converters>
 3             <bean class="org.springframework.http.converter.StringHttpMessageConverter">
 4                 <!-- <constructor-arg ref="utf8Charset"/> -->
 5                  <!-- <property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" /> -->
 6                  <property name="writeAcceptCharset" value="false" /><!-- 用于避免响应头过大 --> 
 7                  <property name = "supportedMediaTypes">
 8                     <list>
 9                         <value>text/plain;charset=UTF-8</value>   
10                         <value>text/html;charset=UTF-8</value>   
11 <!--                         <value>text/json;charset=UTF-8</value>    -->
12                     </list>   
13                  </property>
14             </bean>
15             <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
16                  <property name = "supportedMediaTypes">
17                     <list>
18                         <value>text/json;charset=UTF-8</value>   
19                     </list>   
20                  </property>
21                 
22             </bean>
23         </mvc:message-converters>
24     </mvc:annotation-driven>