0

我正在尝试构建一个可以一次接收多个 id 的 URL,因此我可以一次返回两个人,但是我得到了一个数字格式异常

String url = "http://test.com/Services/people/{id}/Identifier"
Map<String, String> params = new HashMap<String, String>();
params.put("id", {"1234","5678"});
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
                                    .queryParam("DOB", "myDOB");
String uriBuilder = builder.build().encode().toUriString();
restTemplate.exchange(uriBuilder , HttpMethod.PUT, requestEntity,
                class_p, params);

这是通过传入多个 id 获得数字格式异常,有没有办法以不同的格式做到这一点?

4

1 回答 1

2

GET /Services/people/42是对 id 的“人”资源的请求42

根据某些条件对多人的请求不是资源请求,而是查询,因此应该使用查询参数。
例如GET /Services/people/find?id=13&id=29
,或者可能POST /Services/people/find带有有效负载{"id": [1234, 5678]} (Content-Type: application/json)

对于 RESTful 服务,您尝试做的是错误的。

于 2020-05-13T15:58:07.533 回答