本文介绍RestTemplate访问Rest

demo

package com.springlearn.learn;

import java.util.Arrays;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate; @SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(new MediaType[]{MediaType.APPLICATION_JSON_UTF8})); // Get
// HttpEntity<String> entity = new HttpEntity<String>(headers);
// RestTemplate restTemplate = new RestTemplate();
// ResponseEntity<String> response = restTemplate.exchange("https://www.baidu.com/s?wd=a", HttpMethod.GET, entity,String.class); // Post
// HttpEntity<Object> entity = new HttpEntity<>(new Object[]{"1"}, headers);
// RestTemplate restTemplate = new RestTemplate();
// Object response = restTemplate.postForObject("https://www.baidu.com/s?wd=a", entity, Object.class); // Put 和Post类似
// 使用put方法即可
// 或者使用restTemplate.exchange("...", HttpMethod.PUT, entity, String.class); // Delete 直接delete即可 System.out.println("结果:"+response); SpringApplication.run(DemoApplication.class, args);
}
}

springboot成神之——RestTemplate访问Rest的更多相关文章

  1. springboot成神之——ioc容器(依赖注入)

    springboot成神之--ioc容器(依赖注入) spring的ioc功能 文件目录结构 lang Chinese English GreetingService MyRepository MyC ...

  2. java成神之——HttpURLConnection访问api

    HttpURLConnection 访问get资源 访问post资源 访问Delete资源 获取状态码 结语 HttpURLConnection 访问get资源 HttpURLConnection c ...

  3. springboot成神之——springboot入门使用

    springboot创建webservice访问mysql(使用maven) 安装 起步 spring常用命令 spring常见注释 springboot入门级使用 配置你的pom.xml文件 配置文 ...

  4. springboot成神之——mybatis和mybatis-generator

    项目结构 依赖 generator配置文件 properties配置 生成文件 使用Example 本文讲解如何在spring-boot中使用mybatis和mybatis-generator自动生成 ...

  5. springboot成神之——swagger文档自动生成工具

    本文讲解如何在spring-boot中使用swagger文档自动生成工具 目录结构 说明 依赖 SwaggerConfig 开启api界面 JSR 303注释信息 Swagger核心注释 User T ...

  6. springboot成神之——监视器

    Spring Boot 的监视器 依赖 配置 书写监视控制器 常用的一些内置endpoint 定义actuator/info特殊endpoint actuator/shutdown需要post请求才能 ...

  7. springboot成神之——log4j2的使用

    本文介绍如何在spring-boot中使用log4j2 说明 依赖 日志记录语句 log4j2配置文件 本文介绍如何在spring-boot中使用log4j2 说明 log4j2本身使用是非常简单的, ...

  8. springboot成神之——mybatis在spring-boot中使用的几种方式

    本文介绍mybatis在spring-boot中使用的几种方式 项目结构 依赖 WebConfig DemoApplication 方式一--@Select User DemoApplication ...

  9. springboot成神之——spring文件下载功能

    本文介绍spring文件下载功能 目录结构 DemoApplication WebConfig TestController MediaTypeUtils 前端测试 本文介绍spring文件下载功能 ...

随机推荐

  1. idea结合git使用

    1.下载安装好git.exe2. 2.安装好以后在cmd输入git 3.在idea配置git环境 4.托管项目到码云 5.登录码云官网,地址就是你在码云注册的账号和密码

  2. Flask ajax 动态html 的javascript 事件失效

    $('.db_edit').click(function(){ $(".editdbproduct").val($(this).parent().parent().find('.e ...

  3. [Hive]HiveServer2概述

    1. HiveServer1 HiveServer是一种可选服务,允许远程客户端可以使用各种编程语言向Hive提交请求并检索结果.HiveServer是建立在Apache ThriftTM(http: ...

  4. android textview xml 属性设置

     android:ems 设置TextView的宽度为N个字符的宽度. android:maxems 设置TextView的宽度为最长为N个字符的宽度.与ems同时使用时覆盖ems选项. andr ...

  5. Tiny4412 Android5.0 定制:编译生成img后如何删除原厂的apk

    在android-5.0.2/build/core/Makefile的315行可以看到,这里是apk生成签名相关的地方. 315 name := $(TARGET_PRODUCT) 316 ifeq ...

  6. keras&tensorflow+分布式训练︱实现简易视频内容问答框架

    内容来源:Keras 之父讲解 Keras:几行代码就能在分布式环境训练模型 把 Keras API 直接整合入 TensorFlow 项目中,这样能与你的已有工作流无缝结合.至此,Keras 成为了 ...

  7. Android 进阶7:进程通信之 AIDL 的使用

    读完本文你将了解: AIDL 是什么 AIDL 支持的数据类型 AIDL 如何编写 AIDL 实例 创建 AIDL 编写服务端代码 编写客户端代码 运行结果 总结 代码地址 Thanks 记得 201 ...

  8. CSS3实现多列纵向滚动

    效果如图: 小程序wxml: <view class='wraper'> <view class="header"> 头部 </view> &l ...

  9. POJ1287 Networking

    解题思路:Kruskal模板题,重复输入的情况,本题是无向图. 见代码: #include<cstdio> #include<algorithm> #include<cs ...

  10. CentOS 6.5添加网易163源

    换国内的yum源. 准备工作,首先备份/etc/yum.repos.d/CentOS-Base.repo              cd /etc/yum.repos.d/ wget http://m ...