最佳答案
我试图传递路径参数和查询参数在一个 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 中
请建议。预先感谢