java 在 RESTEasy 客户端框架中使用 @DefaultValue

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9869359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:42:57  来源:igfitidea点击:

Using @DefaultValue with RESTEasy Client framework

javaweb-servicesrestresteasy

提问by Jean-Michel Garcia

Can we use the @defaultValue annotation when using the RESTEasy client framework ?

我们可以在使用 RESTEasy 客户端框架时使用 @defaultValue 注释吗?

The compiler doesn't complain about this :

编译器不会抱怨这个:

public interface XClient {  

@GET
@Path("/rest/search")
@Produces(MediaType.APPLICATION_XML)    
public String getInformation(
        @QueryParam("partner") @DefaultValue("xxxxxx") String apiKey);
}

But how can I call this getInformation method without passing the apiKey parameter. In a way that the "xxxxxx" value would be taken instead.

但是如何在不传递 apiKey 参数的情况下调用此 getInformation 方法。以某种方式取而代之的是“xxxxxx”值。

Is that possible or am I misunderstanding the @DefaultValue annotation purpose ?

这是可能的还是我误解了@DefaultValue 注释的目的?

EDIT :

编辑 :

This cannot be done using the @DefaultValue annotation. Maybe there is another solution. There is not much documentation about the client side of the RESTEasy framework.

这不能使用 @DefaultValue 注释来完成。也许还有另一种解决方案。关于 RESTEasy 框架客户端的文档并不多。

回答by Jean-Michel Garcia

This cannot be done using the @DefaultValue annotation (Using the Client Framework).

使用@DefaultValue 注释(使用客户端框架)无法做到这一点。

回答by Pau Kiat Wee

@DefaultValueis a parameter annotation that can be combined with any other @*Paramannotations to define a default value where the HTTP request item does not exist.

@DefaultValue是一个参数注解,可以与任何其他@*Param注解结合,在 HTTP 请求项不存在的情况下定义一个默认值。

See here

这里

So it is possible.

所以这是可能的。

回答by Aure77

DefaultValue is used if QueryParam is not set in the url :

如果 url 中未设置 QueryParam ,则使用 DefaultValue :

http://docs.jboss.org/resteasy/docs/2.3.1.GA/javadocs/javax/ws/rs/DefaultValue.html

http://docs.jboss.org/resteasy/docs/2.3.1.GA/javadocs/javax/ws/rs/DefaultValue.html

http://localhost/rest/search-> default value used as apiKey

http://localhost/rest/search-> 用作 apiKey 的默认值

http://localhost/rest/search?partner=1-> "1" is used as apiKey

http://localhost/rest/search?partner=1-> "1" 用作 apiKey