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

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

> http://localhost:9998/helloworld
> http://localhost:9998/helloworld/ $count

第一个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";
    }
}

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

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

最佳答案
找到了答案.将美元符号放在角色类中就可以了.

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

    return "Hello count";
}

以上内容与以下网址相匹配.

> localhost:9998 / helloworld / $count
> localhost:9998 / helloworld / $count /
> localhost:9998 / helloworld / $count?$filter = blah
> localhost:9998 / helloworld / $count /?$filter = blah

相关文章

摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
今天犯了个错:“接口变动,伤筋动骨,除非你确定只有你一个...
Writer :BYSocket(泥沙砖瓦浆木匠)微 博:BYSocket豆 瓣:...
本文目录 线程与多线程 线程的运行与创建 线程的状态 1 线程...