简体   繁体   English

Jax-RS请求映射到@DefaultValue和@QueryParam的操作

[英]Jax-RS request mapping to operation with @DefaultValue and @QueryParam

I wonder how jax-rs (or Jersey as implementation) maps the client request to the actual operation while using @DefaultValue with @QueryParam . 我想知道jax-rs(或Jersey作为实现)如何在将@DefaultValue@QueryParam使用时将客户端请求映射到实际操作。

Assume that you have the following operations in the resource, one returns all the resources and the other returns all with a custom view; 假设您在资源中具有以下操作,一个返回所有资源,另一个返回所有具有自定义视图的资源;

@Path(/v1)
public class MyResource {

    @GET
    @Path(/my-resource)
    public Response getAllResources(){
       ...
    }

    @GET
    @Path(/my-resource)
    public Response getAllResources(@QueryParam("view") @DefaultValue("simple") String view){
       ...
    }
}

In this case, if I call the service as /v1/my-resource , how the mapping would work internally and which operation is picked? 在这种情况下,如果我将该服务称为/v1/my-resource ,则映射将在内部如何工作以及选择哪个操作?

I appreciate if there's any explanation for this in the specification. 我希望在规范中对此有任何解释。

Thanks, 谢谢,

Tugcem. Tugcem。

As Paul correctly mentioned, you should not have more than 1 method for the same resource and web method (and acceptable media type). 正如Paul正确提到的,对于相同的资源和Web方法(以及可接受的媒体类型),您不应使用超过1种方法。 That's true for JAX-RS in general, not just some implementation. 总的来说,对于JAX-RS来说确实如此,而不仅仅是某些实现。 See JAX-RS spec: 请参阅JAX-RS规范:

3.7.2 Request Matching 3.7.2请求匹配
... ...
If there is more than one maximum element, implementations SHOULD report a warning and select one of these types in an implementation dependent manner. 如果最大元素数不止一个,实现应报告警告,并以依赖实现的方式选择这些类型之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM