Ribbon

作者: 赛亚人之神 | 来源:发表于2017-11-27 16:37 被阅读0次
一、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

      本文链接:https://www.haomeiwen.com/subject/jhydbxtx.html