告诉我,如何在Feign客户端或其他中设置参数的默认值?
下面是我的代码。我指定了默认值,但它不起作用:(
服务项目:
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
);
我想为**“code”**参数设置一个默认值。
2条答案
按热度按时间aelbi1ox1#
该问题是这样解决的:
我把这个添加到我正在敲的服务器上的主API中(即,在接收端,而不是在发送端请求)。
必需的是必需=假(而不是 * 必需=真 *)。
qni6mghb2#
如果您想在客户端执行此操作,您可以尝试在FeignClient接口中添加一个默认方法来传递固定值。例如:
在你的服务中你这样称呼它: