若使用默認的json轉換器,則須要以下包;html
<mvc:annotation-driven />
報錯以下:spring
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supportedjson
解決方案:mvc
引入以下包:app
問題既解決。url
若使用外部的其餘json轉換,則須要配置相關的轉換器spa
如:3d
<mvc:annotation-driven> <mvc:message-converters register-defaults="false"> <bean class="org.springframework.http.converter.StringHttpMessageConverter" /> <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /> <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter" /> <!-- 配置fastjson中實現httpMessageConverter接口的轉換器 --> <bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter" > <!-- 加入支持的媒體類型:返回contentType --> <property name="supportedMediaTypes"> <list> <!-- 這裏順序不能寫反,必定先寫text/html,否則IE會出現下載提示 --> <value>text/html;charset:UTF-8</value> <value>application/json;charset:UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <mvc:default-servlet-handler />