1、这里说的是基于spring+springmvc+hibernate框架(其实跟持久层框架也没关系)

2、首先是springmvc的配置,处理json数据都会用到的。第5行是spring-4.x的写法,第6行是spring-3.x的写法。

 1 <!-- 展示前端数据json格式,字符编码utf-8-->
 2       <mvc:annotation-driven >
 3        <mvc:message-converters register-defaults="true">
 4                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
 5             <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
 6             <!-- <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> spring-3.x用这个-->
 7                 <property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
 8             </bean>  
 9             <bean class="org.springframework.http.converter.StringHttpMessageConverter">      
10                 <property name="supportedMediaTypes">
11                     <list>
12                         <value>text/html;charset=UTF-8</value>
13                         <value>text/plain;charset=UTF-8</value>
14                     </list>
15                 </property>
16             </bean>
17             <bean id="fastJsonHttpMessageConverter" class="com.******.util.FastJsonHttpMessageConverter">
18                     <property name="supportedMediaTypes">
19                         <list>
20                             <value>text/html;charset=UTF-8</value><!-- 避免IE出现下载JSON文件的情况 -->
21                         </list>
22                     </property>
23                 </bean>
24         </mvc:message-converters>
25     </mvc:annotation-driven>

3、jackjson jar包的不同

  spring-3.x用

   

 

  spring-4.x用

  

   下载地址:http://repo1.maven.org/maven2/com/fasterxml/jackson/core/

4、xml配置中用到了阿里的fastjson跟spring版本没有关系。

转载于:https://www.cnblogs.com/shii/p/7483517.html

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐