我有这两种资源方法。我想要:
“...path/”匹配#withRoot
“...path”匹配#withoutRoot
@GET
@Path("/")
public void withRoot() {
int x = 0;
}
@GET
@Path("")
public void withoutRoot() {
int x = 0;
}
但目前它只是跳转到#withRoot。我怎样才能实现这个目标?
最佳答案
根据 Jersey 的文档,这是不可能的:
Likewise, by default, a @Path value may or may not end in a '/', it makes no difference, and thus request URLs that end or do not end in a '/' will both be matched.
因此,在这种情况下,将两者分开没有任何意义。而且,你为什么要这么做?如果您想表示两条不同的路径,最好创建两条不同的路线来表示您要公开的每个功能。
关于java - 同时配置 @Path ("") 和 @Path ("/"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49624082/