Jax-RS 中的可选 @PathParam [英] Optional @PathParam in Jax-RS
问题描述
我有一个服务,其中路径的最后一部分是可选的,用户可以同时输入 /mypath/ 和 /mypath/param1/.
I have a service where the last part of the path is optional, the user can both enter /mypath/ and /mypath/param1/.
我尝试使用正则表达式来过滤路径的最后一部分:
I tried to use a regular expression to filter the last part of the path:
@Path("/mypath{param1: (/param1)?}")
我使用 RestEasy 作为我的 JAX-RS 提供程序,代码在 Tomcat 中按预期工作,但是当我在 JBoss 中部署它时,如果我不提交可选部分,我会得到 405 返回码.
I'm using RestEasy as my JAX-RS provider and the code works as expected in Tomcat but when I deploy it in JBoss I get a 405 return code when I do not submit the optional part.
我在这里做错了什么还是不可能以可移植的方式完成此操作?
Am I doing something wrong here or it's not possible to accomplish this in a portable way?
推荐答案
问题是冒号前缺少空格:
The problem was the lack of whitespace before the colon:
@Path("/mypath{param1: (/param1)?}")
应该是:
@Path("/mypath{param1 : (/param1)?}")
显然这是一个错误,因为 规范 使冒号周围的空格可选.我还发现我不是第一个 被这个错误咬了.
Apparently it's a bug, because the specification makes the whitespace around the colon optional. I also found that I'm not the first bitten by this bug.
这篇关于Jax-RS 中的可选 @PathParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!