spring 中的一些错误

 一、报错 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的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值