问题描述
我们可以使用不同的查询参数创建相同的GET URI吗?
Could we create 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.
- 为什么它会这样?
- 有什么办法可以让两个GET方法有不同的查询参数吗?
如果您能引用任何资源,我们将非常感激。
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")
根据:
由于您的数据模型包含两个不同的资源我建议使用不同的路径制作两个休息方法:
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代表一个且只有一个资源,应该没有ov erloading。如果一个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方法:REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!