两个具有不同查询参数的GET方法:REST [英] Two GET methods with different query parameters : REST

查看:110
本文介绍了两个具有不同查询参数的GET方法:REST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用不同的查询参数创建相同的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.


  1. 为什么它会这样?

  2. 有什么办法可以让两个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")

根据 JSR-311规范


此类方法称为sub -resource方法被视为普通的
资源方法(参见第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代表一个且只有一个资源,应该没有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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆