解决406问题

406问题的原因是服务器响应的数据类型和浏览器想要的数据类型不一致。,比如浏览器要json,我们却返回的是html

问题产生的原因是springmvc会自动根据我们请求路径的后缀判断媒体类型。

我们需要在配置文件中配置不让他自己去给我们判断

<!-- 注解驱动 content-negotiation-manager:注册一个自定义的ContentNegotiationManager-->

<mvc:annotation-driven content-negotiation-manager="negotiationManager"/>

<!-- 自定义的ContentNegotiationManager -->

<bean id="negotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">

<!-- false:不根据请求路径后缀判断响应类型,会取消默认的ServletPathContentNegotiationStrategy -->

<property name="favorPathExtension" value="false" />

</bean>


猜你喜欢

转载自blog.csdn.net/qpc672456416/article/details/80828247