一、报错 415
1.前台发送请求时contentType设为json/application (报错:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported)
2.spring配置中配置messageConverter (报错:Content type 'application/json;charset=UTF-8' not supported)
3.少包:jackson(三个),
二、jackson包作用
包作用:@responsebody json输出
配置:
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
</bean>
</list>
</property>
</bean>
根据版本不同 MappingJacksonHttpMessageConverter或MappingJackson2HttpMessageConverter
三、乱码
请求spring配置的后台接口,中文乱码
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value><!-- 避免IE出现下载JSON文件的情况 -->
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<value>text/html;charset=UTF-8</value> 有时写成<value>text/plain;charset=UTF-8</value>
text/html的意思是将文件的content-type设置为text/html的形式,浏览器在获取到这种文件时会自动调用html的解析器对文件进行相应的处理。
text/plain的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理。