Ribbon

一、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 请求
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 以前,当别人夸我脾气好时,我总暗自高兴,认为自己的沟通能力还不错。可越长大越发现,脾气好≠会沟通,因为所谓的“好”...
    小落墨smile阅读 327评论 0 1
  • 转载:http://blog.csdn.net/tskyfree/article/details/8121915 ...
    ldjhust阅读 660评论 0 3
  • 城里很热心很方,就想出来纳个凉,于是决定去云南,嘿嘿一点不草率。 到达普者黑已经是傍晚,找好客栈吃好饭就近逛了逛,...
    xiu二丫阅读 329评论 0 3
  • 语文作业: 把今天学的复韵母iu各写两行,每行后四个带声调,拼读各写两遍,儿歌和拼读读一读。 数学作业: 预备数学...
    瑞睿家阅读 196评论 0 0
  • 从3月8日早上5点出门,就开始了我的跨越之旅。出西安跨渭河,进重庆跨长江。来到解放碑,不但感受了山城人民的热情。 ...
    紫色薰衣草ZY阅读 259评论 0 0