如何在FeignClient中使用多个查询字符串参数调用url? [英] How to call url with multiple query string params in FeignClient?
问题描述
我尝试使用多个查询字符串参数调用Google API.奇怪的是,我找不到办法.
I try to call Google API with multiple query string parameters. And curiously, I can't find a way to do that.
这是我的FeignClient:
This is my FeignClient :
@FeignClient(name="googleMatrix", url="https://maps.googleapis.com/maps/api/distancematrix/json")
public interface GoogleMatrixClient {
@RequestMapping(method=RequestMethod.GET, value="?key={key}&origins={origins}&destinations={destinations}")
GoogleMatrixResult process(@PathVariable(value="key") String key,
@PathVariable(value="origins") String origins,
@PathVariable(value="destinations") String destinations);
}
问题在于&" RequestMapping value
的字符替换为&
The problem is that '&' character of the RequestMapping value
is replace by &
如何避免这种情况?
谢谢!
推荐答案
所有查询参数将通过使用&
字符的拆分自动从url中提取,并映射到方法声明中的相应@RequestParam.
因此,您无需在@RequestMapping批注中指定所有键,而只需在此指定端点值.
All Query parameters will automatically be extracted from the url by a split using the &
character and mapped to the corresponding @RequestParam in the method declaration.
So you don't need to specify all the keys the @RequestMapping annotation and there you should only specify the endpoint value.
为使您的示例正常工作,您只需要将其余端点更改为
For your example to work you just need to change your rest-endpoint to
@RequestMapping(method=RequestMethod.GET)
GoogleMatrixResult process(@RequestParam(value="key") String key,
@RequestParam(value="origins") String origins,
@RequestParam(value="destinations") String destinations);
这篇关于如何在FeignClient中使用多个查询字符串参数调用url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!