路径参数微分问题
我对 Jax-rs @Path 变量有问题,我需要区分以下两个路径参数
- @Path({domain}/{id})
- @Path({domain}/{filename})
示例 url:< br> 1. http://localhost:8080/in.com/lrth09erdfgwe
2. http://localhost:8080/in.com/lrth09erdfgwe.xml
我认为我们需要在路径参数中使用正则表达式!我尝试过但没能得到! 我在 Resteasy 与 spring-mvc 集成中使用此应用程序。 请就这个问题提出建议!
干杯!
I have problem with Jax-rs @Path variable, I need to differentiate the following two pathparams
- @Path({domain}/{id})
- @Path({domain}/{filename})
sample url for both:
1. http://localhost:8080/in.com/lrth09erdfgwe
2. http://localhost:8080/in.com/lrth09erdfgwe.xml
I think we need to use regex in pathparam! I tried it but failed to get it!
I'm using this application in Resteasy integration with spring-mvc.
Plz advice on this issue!
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在参数内放置一个冒号,然后放置一个 RE 模式来匹配它来控制路径参数的匹配,如下所示(其中 RE 为
.+[.].+
,只要中间至少有一个点,它就匹配任何内容):我在我的一项服务中使用它(它使用 Apache CXF,但我相信这是所有 JAX-RS 实现的一项功能)。不过要小心!您可以将路径分隔符与此相匹配,这会使事情变得非常混乱。 (我认为您最好更改 URI 的结构,以免出现歧义,例如
{domain}/id/{id}
和{domain}/files/{文件名}
。我敢打赌您的客户会更快地理解这一点。)You control the matching of path parameter by putting inside the parameter a colon and then an RE pattern to match it, like this (where the RE is
.+[.].+
, which matches anything so long as it has at least one dot somewhere in the middle):I use this in one of my services (which uses Apache CXF, but I believe this is a feature of all JAX-RS implementations). Have a care though! You can match path separators with this, which can make things very confusing. (I think you might be better to change the structure of the URIs so that there is no ambiguity, e.g.,
{domain}/id/{id}
and{domain}/files/{filename}
. I bet your clients will grok that much more rapidly.)