栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

SpringMVC:不一致的映射行为取决于URL扩展名

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringMVC:不一致的映射行为取决于URL扩展名

这不是一个错误,这是一个功能…

正如@axtavt和@rhinds所假定的那样,内容类型周围有些混乱。浏览器发送了正确的消息,

Accept:application/json
但是spring忽略了这一点,并使用url的扩展名(aarrgh)。从文档:

16.16.4配置内容协商

You can configure how Spring MVC determines the requested media typesfrom the client forrequest mapping as well as for content negotiation purposes. Theavailable options are tocheck the file extension in the request URI, the "Accept" header, arequest parameter, aswell as to fall back on a default content type. By default, fileextension in the requestURI is checked first and the "Accept" header is checked next.

解决方案非常简单,因为您可以禁用此“功能”:

@Configuration@EnableWebMvcpublic class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {    @Override    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {        configurer.favorPathExtension(false);    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/443317.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号