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
Using @DefaultValue with RESTEasy Client framework
提问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
回答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