我正在构建一个安静的服务,它需要接受任意数量的参数,而不是下面示例中的参数。
假设以下服务程序
@RequestMapping("/start/id/{id}", RequestMethod.GET)
public void startService(@PathVariable String id) {...}
有一个基于客户端的实现RestTemplate
restTemplate.getForObject("/start/id/{id}", null, id);
问题:但是考虑到它可能有数千个ids
,我必须使用哪些宁静的方法在一个请求中发送所有参数RestTemplate
?我看过建议
- 将请求正文添加到 GET 请求 - 似乎不可能
RestTemplate
? - 在 id 中使用分隔符,(例如,
id1|id2|....|idn
) - 看起来像hack - 首先 PUT 参数,然后发出 GET 来引用 id - 双重请求,似乎不直观
- 添加多个 URL 参数 (
?id=foo&id=bar&.....&id=foobar
)
我知道类似的问题(calling-a-restful-service-with-many-parameters、how-to-create-rest-urls-without-verbs、can-you-build-a-truly-restful-service-that-takes -many-parameters ) 之前已被问过,但我发现很难找到令人满意的答案,或者至少是基于RestTemplate
.