这就是我正在尝试做的事情:
@Path("/finder")
public class Finder {
@Path("/{name}")
public Proxy find(@PathParam("name") String name) {
Object found = /* some object found by name */
return new Proxy(found);
}
}
public class Proxy {
private Object obj;
public Proxy(Object found) {
this.obj = found;
}
@GET
@Path("/")
public String info() {
return /* some meta-information about the object */
}
@Path("/")
public Object passthru() {
return this.obj;
}
}
我正在尝试启用:
GET /finder/alpha -> Proxy.info()
GET /finder/alpha/something -> obj.something()
我走的路对吗?与此同时, Jersey 说:
WARNING: A sub-resource method, public final java.lang.String com.XXX.Proxy.info(),
with URI template, "/", is treated as a resource method
最佳答案
上面的代码一切都很好,除了我不需要 info()
处的 @Path("/")
注释。
关于java - 如何根据后缀有条件地路由 JAX-RS 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4276882/