restTemplate.postForObject两个步骤怎么解决
发布网友
发布时间:2022-04-25 17:01
我来回答
共1个回答
热心网友
时间:2023-05-21 22:46
restTemplate.postForObject两个方法
1、restTemplate.postForObject(url, null, String.class, params);
Example:
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("booking", "42");
uriVariables.put("hotel", "1");
System.out.println(template.expand(uriVariables));
will print:
http://example.com/hotels/1/bookings/42
2、postForObject(URI url, Object request, Class<T> responseType)
url中不用加参数
Create a new resource by POSTing the given object to the URL, and returns the representation found in the response.
The request parameter can be a HttpEntity in order to add additional HTTP headers to the request.