【问题标题】:Resteasy @Path(value = "/") vs @Path(value = "") are they sameResteasy @Path(value = "/") vs @Path(value = "") 它们是一样的吗
【发布时间】:2014-02-21 12:15:09
【问题描述】:

我正在使用 Resteasy。如果我声明一个方法并使用

@Path(value = "/") or @Path(value = "")

关于那个方法。 他们两个是一样的吗?我的意思是http://localhost:8080/testhttp://localhost:8080/test/ 将采用相同的方法。

如果是(这是我的发现)。那么如何识别请求 http://localhost:8080/test and http://localhost:8080/test/ 并将它们映射到单独的函数,我在两个请求中都有单独数量的 get 参数。

【问题讨论】:

  • 不确定,但我猜不是,“/”应该进入根目录(“localhost:8080"),“”应该进入当前目录,与“.”相同

标签: java web-services rest resteasy


【解决方案1】:

根据JAX-RS specification (page 17),第 3.7.3 节将 URI 模板转换为正则表达式:

4. If the resulting string ends with '/' then remove the final character.

因此,@Path(value = "/")@Path(value = "") 将命中相同的方法,因为第一个 @Path 上的尾随 / 将被删除。

因此,请求 http://localhost:8080/testhttp://localhost:8080/test/ 没有彼此不同。

【讨论】:

    猜你喜欢
    • 2020-03-24
    • 2017-08-14
    • 2017-03-23
    • 2012-09-24
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 2013-02-03
    相关资源
    最近更新 更多