1 定义

RestTemplate 是StringBoot提供的一个Rest远程调用工具

2 常用方法

getForObject() - 执行get请求
postForObject() - 执行post请求

3 新建 sp06-ribbon 项目

RestTemplate远程调用工具(Spring Boot)
RestTemplate远程调用工具(Spring Boot)

1)主程序

创建 RestTemplate 实例

RestTemplate 是用来调用其他微服务的工具类,封装了远程调用代码,提供了一组用于远程调用的模板方法,例如:getForObject()、postForObject() 等
RestTemplate远程调用工具(Spring Boot)

2)RibbonController

RestTemplate远程调用工具(Spring Boot)
RestTemplate远程调用工具(Spring Boot)

3)启动服务,并访问测试

RestTemplate远程调用工具(Spring Boot)
RestTemplate远程调用工具(Spring Boot)

相关文章: