PathParam中的嵌入路径

时间:2013-11-12 23:20:24

标签: java jersey jax-rs

我想要构建的API将包含以下资源:

@GET
@Path("document/{embedded_path"})
@Produces("text/plain")
public String getDocument(@PathParam("embedded_path") String path){ ... }

因此可以像这样访问:

http://example.com/document/relative/path/to/document.txt

到目前为止,我没有看到任何内容明确禁止或允许带有'/'字符的资源参数。有可能以这种方式处理吗? (如果重要的话,客户端可能是javascript)

1 个答案:

答案 0 :(得分:2)

这可以通过通配符实现。

@Path("/document/{embedded_path:.*}")

Embedded template parameters are allowed and are of the form

param = "{" *WSP name *WSP [ ":" *WSP regex *WSP ] "}"
name = (ALPHA / DIGIT / "_")*(ALPHA / DIGIT / "." / "_" / "-" ) ; \w[\w\.-]*
regex = *( nonbrace / "{" *nonbrace "}" ) ; where nonbrace is any char other than "{" and "}"