一、Get 服务消费
(1) getForEntity
1. URI restTemplate
UriComponents components = UriComponentsBuilder.fromUriString("http://HELLO-SERVICE/hello?name={name}").build().expand("grandkai").encode("utf-8");
URI uri = components.toUri();
ResponseEntity<String> entity = restTemplate.getForEntity(uri, String.class);
2. restTemplate.getForEntity(String url, Class responseType, Map urlVariables)
Map<String, String> param = new HashMap<>();
param.put("name", "GrandKai");
restTemplate.getForEntity("http://HELLO-SERVICE/hello?name={name}", String.class, param).getBody();
3. restTemplate.getForEntity(String url, Class responseType, String... urlVariables)
return restTemplate.getForEntity("http://HELLO-SERVICE/hello?name={1}", String.class, "grandkai").getBody();
(2) getForObject
重载方法同 getForEntity 是对它的进一步封装,只关心 body 内容
二、Post 请求
1. postForEntity
2. postForObject
3. postForLocation
三、Put 请求
四、Delete 请求