两种具有不同查询参数的GET方法

编程入门 行业动态 更新时间:2024-10-26 06:26:57
本文介绍了两种具有不同查询参数的GET方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们可以创建相同的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.

  • 为什么会这样?
  • 有什么办法可以使两个具有不同查询参数的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规范:

    这类方法称为子资源方法,被视为常规方法资源方法(请参阅第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方法

    本文发布于:2023-10-26 21:49:59,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1531446.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:两种   参数   方法

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!