欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring4.0 MVC請(qǐng)求json數(shù)據(jù)報(bào)406錯(cuò)誤的解決方法

 更新時(shí)間:2017年01月10日 12:41:54   作者:codingcloud  
這篇文章主要為大家詳細(xì)介紹了Spring4.0 MVC請(qǐng)求json數(shù)據(jù)報(bào)406錯(cuò)誤的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Spring4.0 MVC請(qǐng)求json數(shù)據(jù)報(bào)406錯(cuò)誤,如何解決?

解決方法一:

1、導(dǎo)入jackson-core-2.5.1.jar和jackson-databind-2.5.1.jar

2、Spring配置文件添加:

<!-- 避免IE執(zhí)行AJAX時(shí),返回JSON出現(xiàn)下載文件
spring3為:org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
spring4為:org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
 -->  
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
  <property name="supportedMediaTypes">  
    <list>  
      <value>text/html;charset=UTF-8</value>  
    </list>  
  </property>  
</bean>  
 
<!-- 啟動(dòng)Spring MVC的注解功能,完成請(qǐng)求和注解POJO的映射 -->  
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  <property name="messageConverters">  
    <list>  
      <ref bean="mappingJacksonHttpMessageConverter" /><!-- json轉(zhuǎn)換器 -->  
    </list>  
  </property>  
</bean>  

解決方法二:

1、導(dǎo)入第三方(阿里巴巴)的fastjson包,fastjson-1.2.7.jar

2、Spring配置文件添加:

<mvc:annotation-driven> 
  <mvc:message-converters register-defaults="true"> 
    <!-- 避免IE執(zhí)行AJAX時(shí),返回JSON出現(xiàn)下載文件 --> 
    <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> 
      <property name="supportedMediaTypes"> 
        <list> 
          <value>application/json;charset=UTF-8</value> 
        </list> 
      </property> 
    </bean> 
  </mvc:message-converters> 
</mvc:annotation-driven> 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論