zoukankan      html  css  js  c++  java
  • How to use Spring RestTemplate(转)

    How to use Spring RestTemplate

    Spring logo

    1) Overview

    This is a tutorial about how to consume REST service using Spring RestTemplate. You can find here user service application that we are going to use as a REST service.

    Using this, we can call 3rd party REST services or use for implementing microservices.

    2) Dependencies

    We need the following dependency to work with Spring RestTemplate.

    Other than that dependency, we will use the jackson-fasterxml  dependency for convert JSON to/from Object.

    3) Use GET

    3.1) To retrieve a Java Object

    Using getForObject(), directrly convert to the Object.

    3.2) Pass parameters

    Using HashMap, we can pass a parameters also.

    3.2) Get response as a String and convert to the Java Object

    output

    convert String to Java Object.

    4) Use POST

    Normally, The POST method uses for creating a new resource. We’ll create a new user using the POST method.

    5) Use PUT

    PUT method use for updating a exist resource.

    6) Use DELETE

    We can use the DELETE method for removing a resource.

    7) Using exchange()

    We can use the exchange()with all HTTP methods above mentioned.

    7.1) Using exchange send POST request

    7.2)  Using AsyncRestTemplate

    Using AsyncRestTemplate, send REST calls asynchronously.

    Complete examples find here.

  • 相关阅读:
    [转载]在sharepoint里增加PDF图标显示收藏主题
    CuratorFramework开源Zookeeper快速开发框架介绍
    Zookeeper和CuratorFramework实践之:分布式消息队列
    Zookeeper和CuratorFramework实践系列之: 配置管理
    JS 文字向上滚动代码
    sql递归查询问题
    双线单IP和双线双IP机房的区别
    js获取标准北京时间
    ftp 21端口被占用解决办法
    "由于没有远程桌面授权服务器可以提供许可证..."不能远程桌面解决方法
  • 原文地址:https://www.cnblogs.com/yasepix/p/9868634.html
Copyright © 2011-2022 走看看