我无法弄清楚如何将Java List传入Spring RestTemplate调用,然后使用Controller方法中的列表
客户代码:
public String generateInfoOfIds(List<String> ids, String userName, String password){
RestTemplate restTemplate = new RestTemplate();
String response = null;
String url = "https://someservice.com/getInfoOfIds?";
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(userName, password));
response = restTemplate.exchange(url+"ids=" + ids, HttpMethod.GET, null, String.class);
return response;
}
控制器代码:
@RequestMapping(value = "/getInfoOfIds", method = RequestMethod.GET)
public String getInfoOfIds(@RequestParam("ids") List<String> ids) {
String response = myService.doSomeWork(ids);
return response;
}
对控制器本身的调用有效但是List没有正确转换为@RequestParam ID。
如何在Spring中将List从RestTemplate传递给Controller?