【问题标题】:Updating ant style path capture from spring mvc 3.0 to 3.1将 ant 样式路径捕获从 spring mvc 3.0 更新到 3.1
【发布时间】:2012-04-25 17:42:32
【问题描述】:

在 spring 3.0.x 中,我有一个处理程序方法,它的工作原理非常类似于:

@RequestMapping("/foo/{version:\\d+}/**")
public void handleVersionedResource(@PathVariable("version") Long version, HttpServletRequest request, HttpServletResponse response) {
     String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);

     // rest of the code maps path and version to a real resource and serves 
     // content with extra long cache control / expires headers
 }

在 3.0.x 中,ff 请求的 url 是 /foo/12345/some/resource,然后 path = "some/resource"(请求匹配的 ** 部分)。

但是,在 3.1.x 中(尝试使用 3.1.0.RELEASE 和 3.1.1.RELEASE)路径 = 与完整请求路径匹配,因此在我之前的示例中为“/foo/12345/some/resource”。

所以问题是,有没有人有最简单的方法来复制我在 3.0.x 中得到的行为?此外,任何关于为什么这种行为发生变化的见解?我一开始做错了吗?

更新: 重复Spring 3.1.RC1 and PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE - 那里也没有给出好的答案。

【问题讨论】:

    标签: spring-mvc


    【解决方案1】:

    Spring 3.1.RC1 and PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE 建议 HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE 是 Spring 内部的,不应在您的应用程序中使用

    做类似于How to match a Spring @RequestMapping having a @pathVariable containing "/"? 的事情可能是你最好的选择

    【讨论】:

    • 使用第二个链接中的 AntPathMatcher 就像一个魅力
    猜你喜欢
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2011-03-06
    相关资源
    最近更新 更多