当前位置: 首页 > 知识库问答 >
问题:

Spring MVC返回带有点的URL上的HTTP 406

冷涵忍
2023-03-14
@RequestMapping (value = "/delete/{id:.*}", method = RequestMethod.DELETE)
public ResponseEntity<Response> delete(@PathVariable (value = "id") final String id) {
    HttpStatus httpStatus = HttpStatus.OK;
    final Response responseState = new Response( ResponseConstants.STATUS_SUCCESS );
    try {
        POJO pojo = mediaFileDao.findById( id );
        if (pojo != null) {
            delete(pojo);
        } else {
            httpStatus = HttpStatus.NOT_FOUND;
            responseState.setError( "NOT_FOUND" );
        }
    } catch (Exception e) {
        httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
        responseState.setError( e.getMessage() );
    }
    return new ResponseEntity<>( responseState, httpStatus );
}
DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<my.package.response.Response> my.package.Controller.deleteMediaFile(java.lang.String) throws java.lang.Exception]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<my.package.response.Response> my.package.Controller.deleteMediaFile(java.lang.String) throws java.lang.Exception]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<my.package.response.Response> my.package.Controller.deleteMediaFile(java.lang.String) throws java.lang.Exception]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - Invoking ResponseBodyAdvice chain for body=my.package.response.Response@1e66a392
DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - After ResponseBodyAdvice chain body=my.package.response.Response@1e66a392

Spring不会忽略文件扩展名

SpringMVC:依赖于url扩展的不一致映射行为

共有1个答案

凤晨朗
2023-03-14

servlet xml中,关闭Spring的后缀匹配:

<mvc:annotation-driven>
    <mvc:path-matching registered-suffixes-only="true"/>
</mvc:annotation-driven>

这是一个允许调用方指定他们希望如何返回内容的功能,方法是将其作为后缀粘贴在URL的末尾:

GET /user/bob.json
GET /use/bob.jsp

但是100个项目中有99个没有使用这个特性。而当URL的末尾碰巧有点的时候就会出现问题。

 类似资料:
  • Mkdirs()函数在Android11上不起作用。在Android10及更低版本上,一切都运行良好。 代码: 以上代码在Android 10或更低版本的情况下返回true。但在Android11的情况下返回false。清单权限: 注意到要考虑相同的运行时权限(READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE)。 清单应用程序: 我能够在外部存储中写入的唯一

  • 我们用mod_auth_mellon配置了我们的SPA,SP发起的设置运行良好。我们现在想添加动态路由到发起SSO SAML调用的SPA URL的能力。 下面是电流 < li >用户打开URL http://foo.com/user/1 < li >会话已过期,因此SP启动SSO握手,并将用户重定向到IDP (Ping联合)。 < li >用户在IDP上登录,并在成功认证后被重定向到http://

  • 让我预先感谢你的帮助! 我在一个spring boot应用程序中有一个奇怪的行为。我来给你解释一下: 我正在用一些不错的rest-json服务包装一些遗留的Web服务(自定义xml消息)(通过spring-mvc和Spring boots并使用jackson序列化东西) 为了与遗留系统通信,我创建了一个自定义XmlMapper、序列化器和反序列化器。 最后,我创建了一个httpclientconf

  • 我如何告诉Panache查询的结果将是而不是? 谢谢你的回答 编辑:回购代码:

  • 问题内容: 我相信它在某个时候可以工作,但是现在xpath返回null。有人可以帮助我在以下代码中找到我的愚蠢错误吗? 还是即使在setNamespaceAware(false)之后也必须提供NamespaceContext? XML文档在这里: 问题答案: 三个选择是显而易见的。按照我的观点,最简单的顺序是: 将XPath从更改为。有点笨拙,但它将忽略名称空间。如果仍然为您提供零,则说明问题不在

  • 问题是,如果我输入一个正数(所以一切都正确),我必须输入它两次!同样,当我输入一个负数时,我需要输入两次。当我输入一个字符串时,我会得到一个“错误”,所以我想这还算不错。它是这样显示的: Bitte geben Sie die kleinste阳性Zahl des Intervalls Ein:-2 -3 -7 Bitte Geben Sie eine阳性Zahl ein 2