1. 程式人生 > >415錯誤 (Unsupported Media Type 伺服器無法處理請求附帶的媒體格式)

415錯誤 (Unsupported Media Type 伺服器無法處理請求附帶的媒體格式)

一般是前端傳送資料給後臺,後臺不能識別,造成的。 比如json 字串格式{“key”,“value”} 但是傳送過來的資料value ,有引號的,但是key 一般都不帶的。 所以造成後臺無法解析了。比較快捷的一種解決方式,在SpringMVC配置檔案中加段配置即可:(需要導下fastJson 依賴包)

	<mvc:annotation-driven>
	  <mvc:message-converters register-defaults="true">
	    <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">  
	      <property name="supportedMediaTypes" value="application/json"/>
	      <property name="features">
	        <array>
	          <value>WriteMapNullValue</value>
	          <value>WriteDateUseDateFormat</value>
	        </array>
	      </property>
	    </bean>
	  </mvc:message-converters>  
	</mvc:annotation-driven>