2016-12-05 571 views
3

我尝试使用多个查询字符串参数调用Google API。奇怪的是,我找不到一种方法来做到这一点。如何在FeignClient中使用多个查询字符串参数调用url?

这是我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的 '&' 字符由&

替换如何避免这种情况?

谢谢!

回答

4

所有查询参数将通过使用&字符的分割自动从URL中提取出来,并映射到方法声明中相应的@RequestParam。 因此,您不需要指定@RequestMapping注释的所有键,并且您只应指定端点值。

对于示例工作,你只需要你的休息端点变成

@RequestMapping(method=RequestMethod.GET) 
GoogleMatrixResult process(@RequestParam(value="key") String key, 
          @RequestParam(value="origins") String origins, 
          @RequestParam(value="destinations") String destinations); 
+0

好吧,完美,我测试很多东西,但不是这个! – jeremieca

-2

**使用: -

RequestMapping(method=RequestMethod.GET, value="/test/{key}/{origins}/{destinations}") 
     GoogleMatrixResult process(@PathVariable("key") String key, 
            @PathVariable("origins") String origins, 
            @PathVariable("destinations") String destinations); 

然后形成URL 说: -
http://localhost:portnumber/.../key-value/origins-value/destinations-value 并打这个网址,我相信它会为你使用@PathVariable注释**

相关问题