RestTemplate:如何同时发送 URL 和查询参数
2022-08-31 13:23:44
我正在尝试在URL中传递路径参数和查询参数,但我收到一个奇怪的错误。下面是代码
String url = "http://test.com/Services/rest/{id}/Identifier"
Map<String, String> params = new HashMap<String, String>();
params.put("id", "1234");
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
.queryParam("name", "myName");
String uriBuilder = builder.build().encode().toUriString();
restTemplate.exchange(uriBuilder , HttpMethod.PUT, requestEntity,
class_p, params);
我的网址正在变成http://test.com/Services/rest/%7Bid%7D/Identifier?name=myName
我应该怎么做才能使它起作用。我期望参数将id添加到URLhttp://test.com/Services/rest/{id}/Identifier?name=myName
请建议。提前致谢