具有计数正则表达式的 JAX-RS 路径

JAX-RS Path with count regular expression

如果我在 JAX-RS 的正则表达式中使用“{}”指定计数条件@Path,eclipse 会抛出错误。

@Path("/apps/{itemId:\d{10}}")
public Response getItems(...

The @Path annotation value '/apps/{itemId:\d{10}}' is invalid: missing '{' or '}'.

上面的 JAX-RS 路径不是有效路径吗?是由于 Eclipse JAX-RS 验证器问题吗?如果我只指定 @Path("/apps/{itemId}") 就没有错误。

using regex in Path annotation 时不能在变量内使用大括号。改用:

@Path("/apps/{itemId: \d+}")

regex = *( nonbrace / "{" *nonbrace "}" ) ; where nonbrace is any char other than "{" and "}"

理论上您可以使用多个 [0-9]:

来检查 10 个数字
@Path("/apps/{itemId: [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]}")