[英]Multiple path variables in one url
我正在嘗試構建一個 URL 可以一次接收多個 ID,因此我可以一次返回兩個人,但是我收到了一個數字格式異常
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 獲得數字格式異常,有沒有辦法以不同的格式做到這一點?
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 服務,您嘗試做的是錯誤的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.