一、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 请求
Ribbon
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 以前,当别人夸我脾气好时,我总暗自高兴,认为自己的沟通能力还不错。可越长大越发现,脾气好≠会沟通,因为所谓的“好”...