动力节点旗下在线教育品牌  |  咨询热线:400-8080-105 学Java全栈,上蛙课网

restTemplate请求问题?

晓龙爱学习

2020.06.12

大家好,有个问题请教下。在练习springcloud过程中,使用restTemplate的post方法调用,request参数传不传都没有影响,请问下,这里传与不传的区别是什么

添加回答

回答(1)

军哥

老师参与

RestTemplate对象针对post请求,有如下一些方法:

URI postForLocation(String url, @Nullable Object request, Object... uriVariables) throws RestClientException;

URI postForLocation(String url, @Nullable Object request, Map<String, ?> uriVariables)
      throws RestClientException;

URI postForLocation(URI url, @Nullable Object request) throws RestClientException;

<T> T postForObject(String url, @Nullable Object request, Class<T> responseType,
      Object... uriVariables) throws RestClientException;

<T> T postForObject(String url, @Nullable Object request, Class<T> responseType,
      Map<String, ?> uriVariables) throws RestClientException;

<T> T postForObject(URI url, @Nullable Object request, Class<T> responseType) throws RestClientException;
<T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType,
      Object... uriVariables) throws RestClientException;
<T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType,
      Map<String, ?> uriVariables) throws RestClientException;
<T> ResponseEntity<T> postForEntity(URI url, @Nullable Object request, Class<T> responseType)
      throws RestClientException;

这些方法的request参数表示:the Object to be POSTed (may be {@code null}),就是要post提交的对象Object,由于是Object类型,所以可以post各种类型的数据都可以,当然也可以post一个null;

 

时间:06-14 12:37 查看回复 (0) 回复 0 0 举报

回复