Jersey是否支持美元符号JAX-RS的Path注释?

Jer*_*ome 5 java regex jax-rs jersey

我希望能够访问以下其他网址:

第一个URL工作正常.我使用Jersey实现的JAX-RS在$ count URL上遇到了麻烦.

这是资源的代码.

@Path("/helloworld")
public class HelloWorldResource {
    @GET
    @Produces("text/plain")
    public String getClichedMessage() {
        return "Hello World!";
    }

    @GET
    @Path("\\$count")
    @Produces("text/plain")
    public String getClichedMessage(
            @PathParam("\\$count") String count) {

        return "Hello count";
    }
}
Run Code Online (Sandbox Code Playgroud)

我也在@Path和@PathParam中尝试了"$ count",但这也没有用.

注意:如果我从上面的所有代码中删除美元符号,那么它适用于URL localhost:9998/helloworld/count.但是我需要在URL中存在美元符号,因为这将是一个OData生成器应用程序.

Jer*_*ome 3

找到了答案。将美元符号放在字符类中就可以了。

@GET
@Path("{count : [$]count(/)?}")
@Produces("text/plain")
public String getClichedMessageCount(
        @PathParam("count") String count) {

    return "Hello count";
}
Run Code Online (Sandbox Code Playgroud)

上面的内容与下面的 URL 匹配。

  • 本地主机:9998/helloworld/$count
  • 本地主机:9998/helloworld/$count/
  • 本地主机:9998/helloworld/$count?$filter=blah
  • 本地主机:9998/helloworld/$count/?$filter=blah