|
我希望能够访问以下其他网址:
> 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 (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|