RestTemplate

  • SpringWeb提供的轻量级HTTP Client,用于简化HTTP调用
  • 使用方法

    RestTemplate restTemplate = new RestTemplate();
          //用HTTP GET方法请求,并返回一个对象
          String forObject = restTemplate.getForObject("http://localhost:8080/users/1",String.class);
          System.out.println(forObject);
          //占位符
          forObject = restTemplate.getForObject("http://localhost:8080/users/{id}",String.class,1);
          System.out.println(forObject);
          ResponseEntity<String> forEntity = restTemplate.getForEntity("http://localhost:8080/users/{id}",String.class,1);
          System.out.println(forEntity.getBody());
          //获取返回的状态码
          System.out.println(forEntity.getStatusCode());

标签: none

已有 8 条评论

  1. 怎么收藏这篇文章?

  2. 看的我热血沸腾啊www.jiwenlaw.com

  3. 《豁出去了》战争片高清在线免费观看:https://www.jgz518.com/xingkong/107980.html

  4. 阳光复古传奇攻略大全:https://501h.com/lianji/1028.html

  5. 《天国的阶梯》韩国剧高清在线免费观看:https://www.jgz518.com/xingkong/104741.html

  6. 你的才华横溢,让人敬佩。 http://www.55baobei.com/HOQIxI4l9C.html

  7. 《星星回家》短片剧高清在线免费观看:https://www.jgz518.com/xingkong/157176.html

  8. 哈哈哈,写的太好了https://www.lawjida.com/

添加新评论