JAX-RS:多路径
可以做这样的事情吗?
import javax.ws.rs.GET;
import javax.ws.rs.Path;
public class xxx
{
@GET
@Path(value = "path1")
public Response m1()
{
...
}
@GET
@Path(value = "path2")
public Response m1()
{
...
}
}
顺便说一句,我正在使用 RESTEasy。
Is it possible to do something like that?
import javax.ws.rs.GET;
import javax.ws.rs.Path;
public class xxx
{
@GET
@Path(value = "path1")
public Response m1()
{
...
}
@GET
@Path(value = "path2")
public Response m1()
{
...
}
}
I'm using RESTEasy btw.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 Resteasy 文档:
http://docs.jboss.org /resteasy/docs/1.0.2.GA/userguide/html_single/index.html#_Path_and_regular_expression_mappings
From resteasy docs:
http://docs.jboss.org/resteasy/docs/1.0.2.GA/userguide/html_single/index.html#_Path_and_regular_expression_mappings
是的,你可以这样做,尽管你必须重命名你的方法,以便它们的签名不同。
更新: 检查 Dieter Cailliau 的答案,
@Path("/{a:path1|path2}")
可能就是你想要的...你可以检查 JSR-311 的 API 及其名为“jersey”的参考实现:
JSR311 API
泽西岛
yes you can do that although you will have to rename your methods so that their signature is different.
Update: Check Dieter Cailliau's answer,
@Path("/{a:path1|path2}")
is probably what you want...you can check JSR-311's API and it's reference implementation named "jersey" there:
JSR311 API
Jersey
关于路径注释的一些额外细节...
正如之前的响应所述,在注释路径声明映射中使用的正则表达式:
您可以声明多个路径,但还有一个对我来说并不立即明显的路径层次结构,其中类注释路径作为以下方法路径注释的前缀。人们可以编写以下类来获得简洁的多路径选项,这对于资源版本控制可能很有用。
请注意,“BlahResource”类已使用路径“/v1”或“/v2”声明,使得资源可以通过以下方式访问
:
Some extra details about Path annotation...
As a previous responses state, regular expressions to be used with in the annotated path declaration mapping:
You can declare multiple paths, but there is also a path hierarchy that was not immediately obvious to me whereby the class annotated path prefixes the following method path annotations. One might write the following class for a concise multiple path option which could be useful for resource versioning perhaps.
Please note the fact that the class "BlahResource" has been declared with the path "/v1" or "/v2" making the resource accessible as:
and also
您可以使用子资源将两个路径映射到同一资源:
You could use sub resources to map two paths to the same resource: