我们可以创建相同的GET URI,但使用不同的查询参数吗?
Could we create the same GET URI but with different query parameters?
例如,我有两个REST GET URI:
For example, I have two REST GET URIs:
/questions/ask/?type=rest /questions/ask/?byUser=john现在,REST服务无法将两个GET方法识别为单独的,而仅将其声明为第一个GET方法.
Now the REST service is not recognizing two GET methods as separate and considering it only 1 GET method which is declared as first.
如果您能引用任何资源,将不胜感激.
It would be highly appreciated if you could quote any resource.
推荐答案因为资源由其 PATH (而不是其参数)唯一标识.您定义的两个资源具有相同的PATH.
Because a resource is uniquely identified by its PATH (and not by its params). Two resources you define have the same PATH.
@Path("/questions/ask")根据 JSR-311规范:
这类方法称为子资源方法,被视为常规方法资源方法(请参阅第3.3节),仅调用方法用于与通过串联创建的URI模板匹配的请求URI资源类的URI模板与资源类的URI模板方法.
由于您的数据模型包含两种截然不同的资源,所以我建议使用两种不同的路径创建其他休息方法:
Since your data model includes two distinct resources I suggest making two rest methods with different paths:
@Path("/questions/ask/type") @Path("/questions/ask/user")这是RESTful方式,因为一个URI表示一个且仅一个资源,因此不应有任何重载.如果一个URI代表不止一种资源,则意味着您在某处错了.
This is the RESTful way, since one URI represents one and only one resource and there should be no overloading. If one URI represents more than one resource that means you got it wrong somewhere.
更多推荐
两种具有不同查询参数的GET方法
发布评论