我正在尝试在 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
我应该怎么做才能让它工作。我期待http://test.com/Services/rest/{id}/Identifier?name=myName
这样params会将id添加到url
请建议。提前致谢