Java:Feign客户端中的默认值 [英] Java: default value in Feign client
本文介绍了Java:Feign客户端中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
告诉我,如何在Feign客户端或其他客户端的参数中设置默认值?
Tell me, how can I set the default value in a parameter in the Feign client or other?
这是我的代码.我指定了默认值,但它不起作用:(
Here is my code. I indicated the default value, but it does not work :(
服务:
public Price get(PricesRequest request) {
return priceFeignClient.get(
request.getPrice(),
request.getAddress(),
request.getCode(),
request.getCurrency()
)
}
假客户:
public interface PriceFeignClient {
@GetMapping
Price get(@RequestParam("price") String price,
@RequestParam("address") String Address,
@RequestParam(value = "code", required = true, defaultValue = "AAA") String code,
@RequestParam("currency") String currency
);
我想为代码" 参数设置默认值.
I want to make a default value for the "code" parameter.
推荐答案
问题解决如下:
将此添加到我敲过的服务器上的主api中(即,在接收方,而不是在发送方请求上).
added this to the main api on the server that I was knocking on (i.e., on the receiving side, and not on the sending side request).
@RequestParam(value = "code", required = false, defaultValue = "AAA") String code
必填项是 required = false (而不是 required = true ).
这篇关于Java:Feign客户端中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文