【问题标题】:How to route JAX-RS request conditionally, depending on the suffix?如何根据后缀有条件地路由 JAX-RS 请求?
【发布时间】:2010-11-25 12:08:38
【问题描述】:

这就是我想要做的:

@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()

我走对了吗?与此同时,泽西说:

WARNING: A sub-resource method, public final java.lang.String com.XXX.Proxy.info(), 
with URI template, "/", is treated as a resource method

【问题讨论】:

    标签: java jersey jax-rs


    【解决方案1】:

    上面的代码一切正常,除了我不需要info() 处的@Path("/") 注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 2011-06-14
      • 2013-07-13
      • 2017-11-05
      • 2012-12-29
      • 2023-03-09
      • 2022-01-21
      相关资源
      最近更新 更多