IT常识
技术 Python PHP JavaScript IOS Android Java 数据库 资源 公众号 代码片段 github
  • IT常识
  • 资源

微服务那点事

Posted 2021-01-10

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微服务那点事相关的知识,希望对你有一定的参考价值。

今天用到了RestTemplate,提供了多种便捷远程访问http服务的方法。br/>是一种简洁的访问restful服务模板类,是spring提供的用于访问客户端的模板工具集。
使用时要携带三个参数:(url,requestMap,ResponseBean.class)
分别是rest的请求地址,传入的参数,http响应转换被转换的类型
@Configuration
public class Configbean {

@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


以上是关于微服务那点事的主要内容,如果未能解决你的问题,请参考以下文章

细说微服务架构的优势与不足那点事

细说微服务架构的优势与不足那点事

CIO:微服务(Microservice)那点事

小程聊微服务-数据抽取那点事

小程聊微服务-数据抽取那点事

微信支付服务商开发相关的那点事

(c)2006-2024 SYSTEM All Rights Reserved IT常识