代码之家  ›  专栏  ›  技术社区  ›  yegor256

如何根据后缀有条件地路由JAX-RS请求?

  •  0
  • yegor256  · 技术社区  · 14 年前

    这就是我要做的:

    @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
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   yegor256    14 年前

    上面的代码一切都很好,除了我不需要 @Path("/") 注释位于 info() .