1. 启动中加入RestTemplate
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
2.控制层中调用RestTemplate中的各种方法
//通过pid获取另一个服务中的Product对象
Product product =restTemplate.getForObject("http://localhost:8081/product/" + pid, Product.class);
网友评论