1. 程式人生 > >微服務那點事

微服務那點事

boolean fix ebe 詳細 res return 遠程 resp vat

今天用到了RestTemplate,提供了多種便捷遠程訪問http服務的方法。是一種簡潔的訪問restful服務模板類,是spring提供的用於訪問客戶端的模板工具集。
使用時要攜帶三個參數:(url,requestMap,ResponseBean.class)
分別是rest的請求地址,傳入的參數,http響應轉換被轉換的類型
@Configuration
br/>是一種簡潔的訪問restful服務模板類,是spring提供的用於訪問客戶端的模板工具集。
使用時要攜帶三個參數:(url,requestMap,ResponseBean.class)
分別是rest的請求地址,傳入的參數,http響應轉換被轉換的類型
@Configuration
@Bean
public RestTemplate getRestTemplate() {
    return new RestTemplate();
}

controller層

@Autowired
private RestTemplate restTemplate;

@RequestMapping("/consumer/dept/add")
public boolean add(Dept dept) {

    return restTemplate.postForObject(REST_URL_PREFIX, dept, Boolean.class);
}

詳細可進入官網查看:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html

微服務那點事