Spring boot restTemplate

RestTemplate 配置及使用 RestTemplate 是从 Spring3.0 开始支持的一个 HTTP 请求工具,它提供了常见的REST请求方案的模版,例如 GET 请求、POST 请求、PUT 请求、DELETE 请求以及一些通用的请求执行方法 exchange 以及 execute。 阅读详情

Spring boot restTemplate

上一节 spring boot 数据库连接池

spring boot 数据库连接池

源码

源码地址


Spring boot restTemplate

简介
restTemplate 是spring 提供的进行http 访问的工具;spring boot 中已经配置好了;

springboot 中 对 restTemplate 的支持

在 RestTemplateAutoConfiguration 中可以看到 已经创建了 bean, RestTemplateBuilder (注意springboot版本,我的为2.1.6)

	@Bean
   @ConditionalOnMissingBean
   public RestTemplateBuilder restTemplateBuilder() {
   	RestTemplateBuilder builder = new RestTemplateBuilder();
   	HttpMessageConverters converters = this.messageConverters.getIfUnique();
   	if (converters != null) {
   		builder = builder.messageConverters(converters.getConverters());
   	}

   	List<RestTemplateCustomizer> customizers = this.restTemplateCustomizers.orderedStream()
   			.collect(Collectors.toList());
   	if (!CollectionUtils.isEmpty(customizers)) {
   		builder = builder.customizers(customizers);
   	}
   	return builder;
   }

在项目中使用,配置RestTemplate

添加配置类, 配置 restTemplate

@Configuration
@ConditionalOnClass(RestTemplate.class)
public class RestTemplateConfig {
@Bean
 public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
     return restTemplateBuilder
     // 配置 readTimeout
     .setReadTimeout(Duration.ofSeconds(5))
     // 配置 连接超时
     .setConnectTimeout(Duration.ofSeconds(2)).build();
 }

}

项目中使用 只需要引入一下即可

    @Autowired
    private RestTemplate restTemplate;

restTemplate 重要参数

url: 请求地址
responseType: 返回值类型
uriVariables: url 变量值
Object request: 请求体;可以是个httpEntity;若为其他,则会创建一个httpEntity ,request为 httpEntity 的body
HttpEntity: 请求参数,可以设置body, headers
responseEnity: 请求返回值,包含具体的body, headers, httpstatus 等http信息

restTemplate GET POST PUT DELETE 操作 传参

get 请求

  • getForObject
// 接收url 和 responseType
restTemplate.getForObject(JDBC_DEMO_URL + "/user/" + id, UserEntity.class);
// url传参; 使用 模板占位符 {index};进行传参,Object... uriVariables 按照index顺序进行传参
// 例如 url = /user/batch?ids={0}&ids={1}, 参数 uriVariables可变数组按照顺序传参;
// 注意: 这里的 collect 是我封装好的 = ‘?ids={index}’;例如   /user/batch?ids={0}&ids={1}
restTemplate.getForObject(JDBC_DEMO_URL + "/user/batch" + collect, List.class, ids);
// url传参, 同时模板占位符 {feild}进行传参, 使用 map  uriVariables 进行参数赋值
// 例如  url = /user/batch?uName={name}&password={password};
// params = new Map(); put(name,name),put(password,password)
restTemplate.getForObject(JDBC_DEMO_URL + "/user/batch" + collect, List.class, params);
  • getForEntity
    getForEntity 和 getForObject 使用方式一样;只是返回的类型不一样;
    getForEntity 返回 responseEntity, 可以有更具体的信息, body, headers, httpstatus 等信息;

ForENtity 和ForObject 请求使用是一样的 只是返回值不同;以下只使用其中的一种。


Post 请求

postForObject

     public List<String> batchAddUser(@RequestBody List<UserEntity> userEntities) throws Exception {
        return restTemplate.postForObject(JDBC_DEMO_URL + "/user/batch", userEntities, List.class);
    }

参数userEntities; 是请求体,会封装到httpEntity 的body中;

post 请求的所有方法: 具体的参数可以参考restTemplate 重要参数
在这里插入图片描述

Put 请求

 restTemplate.put(JDBC_DEMO_URL + "/user", userEntity);

delete 请求

  Map<String, String> map = new HashMap<>();
        map.put("id", id);
        // 使用{field}占位符,进行参数映射
        restTemplate.delete(JDBC_DEMO_URL + "/user/{id}", map);
    }

使用 exchange

  restTemplate.exchange(JDBC_DEMO_URL + "/user", HttpMethod.PUT, new HttpEntity<>(userEntity), Void.class);

总结: restTemplate 进行http 请求使用很简单,主要注意 1.使用占位符进行参数赋值。 2. 对请求参数 request 的使用, 是使用 实体类,还是httpEntity; 使用还是很简单的 见名知意。

restTemplate Form表单提交

form 表单提交,我们需要传递一个httpEntity ,并设置 body 为 multivalueMap;

 public String addUser(@RequestBody UserEntity userEntity) throws Exception {
        // 模拟form 表单提交,form 表单提交body 需要为 MultiValueMap
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, Object> p = new LinkedMultiValueMap<>();
        p.add("uName", userEntity.getuName());
        p.add("password", userEntity.getPassword());
        p.add("money", userEntity.getMoney());
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(p, headers);
        return restTemplate.postForEntity(JDBC_DEMO_URL + "/user", httpEntity, String.class).getBody();
    }

restTemplate FileUpload

使用spring 框架的时候 通常我们上传文件 都是使用的 multipartFile 进行接收。

  1. restTemplate 上传文件,使用MultipartFile 接收
    例如对方代码: 上传文件 使用multipartFile 接收
 @PostMapping("file")
    public void upload(@RequestPart(name = "file") MultipartFile file) throws Exception

使用restTemplate 调用该接口

  • 使用FileSystemResource 上传; 需要借助临时文件, FileSystemResource 需要传入一个File,
    所以我们需要创建一个临时的file
    // 通过fileSystemResource 进行文件上传, 使用multipartFile 接收;缺点需要通过创建临时文件上传,以及使用完后不能再次使用
    private void uploadByFileSystemResource(MultipartFile file) throws Exception {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        File tempFile = new File(Files.createTempDir().getPath() + "/" + file.getOriginalFilename());
        file.transferTo(tempFile);
        FileSystemResource fileSystemResource = new FileSystemResource(tempFile);
        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
        param.add("file", fileSystemResource);
        HttpEntity httpEntity = new HttpEntity<>(param, headers);
        restTemplate.postForEntity(JDBC_DEMO_URL + "/user/file", httpEntity, Void.class);
    }
  • 使用 inputStreamResource 或者byteArrayResource
    这里我们需要使用 两个 httpEntity;
  private void uploadBy(MultipartFile file) throws Exception {
        // ByteArrayResource 和InputStreamResource 都可以
        ByteArrayResource byteArrayResource = new ByteArrayResource(file.getBytes());
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.parseMediaType(Objects.requireNonNull(file.getContentType())));
        httpHeaders.setContentDispositionFormData("file", file.getOriginalFilename());
        HttpEntity<ByteArrayResource> bodyHttpEntity = new HttpEntity<>(byteArrayResource, httpHeaders);
        MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
        body.add("file", bodyHttpEntity);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(body, headers);
        restTemplate.postForEntity(JDBC_DEMO_URL + "/user/file", httpEntity, Void.class);
    }
  1. 上传文件到body中,通过request.getInputStream 接收文件
    例如 :
    接收上传文件的代码示例:
 // 上传文件,配合restTemplate 使用
    @PostMapping("file2")
    public void upload(HttpServletRequest request) throws Exception {
        FileOutputStream fileOutputStream = new FileOutputStream("F:\\app\\aaa.jpg");
        IOUtils.copy(request.getInputStream(), fileOutputStream);
        IOUtils.closeQuietly(fileOutputStream);
    }
  • 上传文件,使用InputStreamResource 上传
    // 通过InputStreamResource 上传, 通过request.getInputStream 接收
    private void uploadByInputStreamResource(MultipartFile file) throws Exception {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.parseMediaType(file.getContentType()));
        InputStreamResource inputStreamResource = new InputStreamResource(file.getInputStream());
        HttpEntity httpEntity = new HttpEntity<>(inputStreamResource, httpHeaders);
        restTemplate.postForEntity(JDBC_DEMO_URL + "/user/file2", httpEntity, Void.class);

    }
  • 使用byteArrayResource 上传
    private void uploadByByteArrayResource(MultipartFile file) throws Exception {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType(file.getContentType()));
        ByteArrayResource byteArrayResource = new ByteArrayResource(file.getBytes());
        HttpEntity httpEntity = new HttpEntity<>(byteArrayResource, headers);
        restTemplate.postForEntity(JDBC_DEMO_URL + "/user/file2", httpEntity, Void.class);
    }

restTemplate 配置使用HttpClient

restTemplate 默认使用的是 SimpleClientHttpRequestFactory 进行获取http连接的;SimpleClientHttpRequestFactory 是使用的使用JDK 提供的java.net.HttpURLConnection 获取连接;

也可以配置restTemplate 使用 apache 的 httpClient

1.加入httpClient 依赖

<dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.9</version>
        </dependency>

加入 httpClient 依赖后; restTemplate 就自动选择httpClient 进行http请求; 如何自动选择的可以参考ClientHttpRequestFactorySupplier ;

但是一般我们不想使用默认的配置; 可以配置相关的http连接信息
2. 配置自定义HttpClient连接信息

@Configuration
@ConditionalOnClass(RestTemplate.class)
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
        return restTemplateBuilder/*.setReadTimeout(Duration.ofSeconds(5)).setConnectTimeout(Duration.ofSeconds(2))*/.build();
    }

    @Configuration
    @ConditionalOnClass(HttpClient.class)
    @EnableConfigurationProperties(HttpClientProperties.class)
    public static class HttpClientConfig {

        @Autowired
        private HttpClientProperties httpClientProperties;

        // 配置 httpClient
        @Bean
        public HttpClient httpClient() {
            HttpClientBuilder customHttpClient = HttpClients.custom();
            RequestConfig.Builder customRequestConfig = RequestConfig.custom();
            customRequestConfig.setConnectionRequestTimeout(httpClientProperties.getConnectionTimeout()) // 获取连接超时时间
                    .setSocketTimeout(httpClientProperties.getReadTimeout()) //
                    .setConnectTimeout(2000); // 建立连接超时时间
            customHttpClient.setConnectionManager(httpClientConnectionManager())
                    .setDefaultRequestConfig(customRequestConfig.build())
                    .evictIdleConnections(httpClientProperties.getMaxIdleTime(), TimeUnit.SECONDS) // 连接空闲时间,超时驱逐
                    .disableAutomaticRetries(); // 禁止自动重试

            return customHttpClient.build();
        }

        // 配置 httpClientConnectionManager 连接请求管理者
        @Bean
        public HttpClientConnectionManager httpClientConnectionManager() {
            PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
            poolingHttpClientConnectionManager.setMaxTotal(httpClientProperties.getMaxConnectionTotal()); // 池中最大连接总数
            int defMaxPerRoute = httpClientProperties.getMaxConnectionTotal() / 10;
            if (defMaxPerRoute <= 0) defMaxPerRoute = 1;
            poolingHttpClientConnectionManager.setDefaultMaxPerRoute(defMaxPerRoute); // 最大路由
            return poolingHttpClientConnectionManager;
        }
        
        // 配置 httpRequestFactory 这个是spring提供的
        @Bean
        public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory(HttpClient httpClient, RestTemplate restTemplate) {
            HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
            restTemplate.setRequestFactory(httpComponentsClientHttpRequestFactory);
            return httpComponentsClientHttpRequestFactory;
        }

    }

连接配置类

@ConfigurationProperties(prefix = "httpclient.config")
@Data
public class HttpClientProperties {

  private Long connectionTimeout = 2000L; // 2s

    private Long readTimeout = 10000L; // 10s

    private Integer maxConnectionTotal = 30; // 30

    private Integer maxIdleTime = 180; // 180s


}

配置文件中配置相关属性

  httpclient:
  config:
    connection-timeout: 3000
    read-timeout: 10000
    max-connection-total: 1
    max-idle-time: 30

restTemplate 配置使用OkHttp

OkHttp 优缺点就不说了; 网上一大批;我们就使用restTemplate 整合下Okhttp。

创建使用 Okhttp的restTemplate

    @Bean
    public RestTemplate restTemplateOkHttpClient(RestTemplateBuilder restTemplateBuilder) {
        return restTemplateBuilder.build();
    }

配置Okhttp

    @Configuration
    @ConditionalOnClass(OkHttpClient.class)
    public static class OkHttpClientConfig {

        @Bean
        public OkHttpClient okHttpClient() {
            OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
            return okHttpClient.build();
        }

        @Bean
        public OkHttp3ClientHttpRequestFactory okHttp3ClientHttpRequestFactory(@Qualifier("restTemplateOkHttpClient") RestTemplate restTemplateOkHttpClient) {
            OkHttp3ClientHttpRequestFactory okHttp3ClientHttpRequestFactory = new OkHttp3ClientHttpRequestFactory();
            // 设置restTemplate 使用 okHttpRequestFactory
            restTemplateOkHttpClient.setRequestFactory(okHttp3ClientHttpRequestFactory);
            okHttp3ClientHttpRequestFactory.setWriteTimeout(15000);
            okHttp3ClientHttpRequestFactory.setConnectTimeout(3000);
            okHttp3ClientHttpRequestFactory.setReadTimeout(15000);
            return okHttp3ClientHttpRequestFactory;
        }
    }

项目中引用并使用

 @Autowired
    @Qualifier("restTemplateOkHttpClient")
    RestTemplate restTemplateOkHttpClient;
...
// 正常使用restTemplate 请求方法即可
 restTemplateOkHttpClient.postForObject(JDBC_DEMO_URL + "/user/batch", userEntities, List.class);

restTemplate 配置请求拦截器

例如记录请求详情和时间
创建 LogClientHttpRequestInterceptor 继承 ClientHttpRequestInterceptor

@Slf4j
public class LogClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        Stopwatch stopwatch = Stopwatch.createStarted();
        String method = request.getMethodValue();
        String uri = request.getURI().toString();
        ClientHttpResponse response = execution.execute(request, body);
        log.warn("\n【\t{}  [{}] \n body: {} \n 请求耗时:{}ms】", uri, method, new String(body, StandardCharsets.UTF_8), stopwatch.elapsed(TimeUnit.MILLISECONDS));
        return response;
    }
}

在创建restTemplate 是加入拦截器

 return restTemplateBuilder.additionalInterceptors(new LogClientHttpRequestInterceptor()).build();

使用该rest Template 请求输出日志

2021-04-14 17:18:18.480  WARN 59112 --- [nio-7474-exec-1] c.x.r.c.LogClientHttpRequestInterceptor  : 
【	http://localhost:8989/user/batch  [POST] 
 body: [{"uId":null,"uName":"xxx","password":"111","money":0,"createTime":null},{"uId":null,"uName":"yyyy","password":"11","money":0,"createTime":null}] 
 请求耗时:163ms】

下一节 Spring boot servlet,filter,Interceptor

spring boot servlet, filter , interceptor

Springboot 开发之 RestTemplate 简介 可以通过设置ClientHttpRequestFactory来自定义RestTemplate的配置,如使用HttpComponentsClientHttpRequestFactory(基于Apache HttpClient)或OkHttp3ClientHttpRequestFactory(基于OkHttp)等。可以配置连接池、超时时间、请求和响应的编解码等。 阅读详情

相关推荐

Spring boot注入RestTemplate实例的2种方式

RestTemplate是我们使用的比较多的模板,用来发送http请求。大多数情况下,需要我们自己注入到Spring IOC容器。 对于低版本的spring boot,比如spring boot 1.3.7,是不支持RestTemplateBuilder创建RestTemplate实例的。 怎么办呢,如下: @Bean public RestTemplate restTemplate() { return new RestTemplate(); } 如果是spring boo...

reggergdsg的博客 5518

微服务学习系列8:RestTemplate

在java的http开发中,访问第三方网络接口,通常使用的连接工具为HttpClient和OKHttp。这两种连接工具,使用起来比较复杂,新手容易出问题。如果我们使用的是spring框架,可以使用R来进行http连接请求。RestTemplate默认的连接方式是java中的,可以使用指定不同的HTTP连接方式。例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

yangyanping20108的博客 572

SpringBoot2.x系列教程(六十七)Spring Boot注入RestTemplate及源码解析

引入SpringBoot本来就支持REST服务,因此在SpringBoot项目之间经常需要通过REST的形式来相互调用。本文以具体的实例带大家了解一下SpringBoot中怎么使用RestTemplate进行接口调用。同时,会讲解部分相关源码。 RestTemplate的实例化 RestTemplate实例通常需要自己进行定制,SpringBoot相关的自动配置bean。但是,SpringBoot提供了自动配置的RestTemplateBuilder,可以用它来创建RestTemplate实例。 那么,Sp

程序新视界 1830

Spring自动配置之---RestTemplateAutoConfiguration学习

@Configuration @AutoConfigureAfter(HttpMessageConvertersAutoConfiguration.class) @ConditionalOnClass(RestTemplate.class) public class RestTemplateAutoConfiguration { private final ObjectProvider&...

雪落南城的博客 3765

Spring Boot Introducing the RestTemplate

RestTemplate是Spring Framework提供的一个用于访问RESTful服务的客户端模板类,主要用来简化客户端调用HTTP请求的开发流程,并增加了一些特定于REST的功能特性。RestTemplate支持GET、POST、PUT、DELETE等HTTP方法,可以直接传入请求参数,也可以通过封装的实体对象发送请求。本文将对RestTemplate进行详细的介绍,并结合实例代码加以说明。

AI天才研究院 2576

Spring Boot中RestTemplate的高级封装与应用

在Spring Boot应用中,创建实例最简单的方式是利用Spring的依赖注入功能。通过在类上添加@Autowired注解,Spring会自动注入的Bean。以下是创建实例的一个基本示例:@Component@Autowired// 其他业务逻辑代码...在这个示例中,被定义为一个Bean,并通过构造器注入到RestClient类中。这种方式简化了实例的创建过程,且自动利用了Spring的生命周期管理功能。

weixin_42393362的博客 1484

spring boot 工具类注入 restTemplate

前言: 在我们用springboot 开发项目的过程用,会有调用第三方http接口的情况,这时我们使用spring的RestTemplate,使用更方便。 1,我们可以自己看下RestTemplate源码,提供了好多请求格式,你可以自己选择使用。具体方法说明网上都有,常用的getForEntity,getForObject,postForObject,postForEntity,exchange...

360linker 3212

保姆级教程:用杰理701N可视化SDK搞定ANC降噪配置(从工具到代码全流程)

本文提供了一份详细的杰理701N可视化SDK配置ANC降噪功能的教程,涵盖从开发环境搭建到代码集成的全流程。通过图形化工具和代码示例,帮助开发者快速掌握ANC参数配置技巧,优化降噪效果,解决常见问题。

weixin_30616969的博客 450

使用RestTemplate消费spring boot的Restful服务

一、RestTemplate说明     RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率。前面的博客中http://blog.csdn.net/liuchuanhong1/article/details/53537874,已经使用Jersey客户端来实现了消费spring

牛奋lch 5万+

Ubuntu 22.04下Nvidia显卡驱动安装全攻略:从PPA源到避坑指南

本文详细介绍了在Ubuntu 22.04系统下安装Nvidia显卡驱动的完整流程,包括PPA源的使用、旧驱动清理、安装后验证及常见问题解决方案。特别针对机器学习开发者和图形设计师,提供了从基础安装到性能调优的全方位指南,帮助用户避免常见安装陷阱并优化GPU性能。

weixin_29213655的博客 381

7-1 链式基数排序 (20 分)

7-1 链式基数排序 (20 分) 实现链式基数排序,待排序关键字n满足1≤n≤1000,最大关键字数位≤5。 输入样例: 第一行输入待排序个数n(1≤n≤1000),再输入n个数(n的数位≤5)。 10 278 109 63 930 589 184 505 269 8 83 输出样例: 输出每趟分配-收集后链表中的关键字,趟数为序列中最大值的数位(如样例中930的数位为3),每行结尾有空格。 930 63 83 184 505 278 8 109 589 269 505 8 109 930 63 26

OwemShu的博客 4236

Spring Boot 开发RestTemplate使用

Spring Boot 开发RestTemplate使用

码海浮生,一个乐于分享的全栈工程师! 1449

线上专利申请(超详细)| 签名确认

在【法人登录】页面点击【证书登录】按钮,弹出证书登录提示框,点击【确 认】按钮,进入到输入证书密码页面,点击【取消】按钮,取消本次操作。企业在提交申请时,需要增加签名,如使用企业账户点击提交,会弹出“法人、代理机构不能签名,请使用经办人签名”,这个时候就需要换个账号了。在需要签名时,将专利官网的登录方式点击法人登录,选择扫码登录,使用移动端经办人账户的扫一扫功能扫描登录。登录完成后,再点击签名,使用移动端扫一扫功能,扫描签名,输入证书号,确认签名,并提交。最后,祝大家的申请都成功!

weixin_62112323的博客 9108

Spring Boot中RestTemplate的使用

使用spring进行REST 1.SpringBoot 使用RestTemplateBuilder配置RestTemplate //首先,在springboot启动类中,或者配置类中进行配置 @Autowired RestTemplateBuilder restTemplateBuilider; @Bean public RestTemplate restTemplate() { //使用bui...

Pruett的博客 8666

3D点云处理:PointNet++与PointTransformer的对比

摘要: 3D点云处理中,PointNet++和PointTransformer是两种主流深度学习模型。PointNet++通过分层采样和分组策略提取局部特征,而PointTransformer利用自注意力机制捕捉全局上下文。实验表明,PointTransformer在分类(ModelNet40准确率92.1%)和分割(ShapeNet mIoU 85.7%)任务上性能更优,但计算开销较大(训练时间180秒/轮)。PointNet++在实时性场景更具优势(训练时间120秒/轮)。未来可结合两者优势,或优化Tr

shejizuopin的博客 1117

Cesium 实战 28 - 三维视频融合(视频投影)

Cesium 实战 27 - 三维视频融合(视频投影)。

非科班Java出身GISer的博客 3366

【spring boot】 使用 RestTemplate

略

sayyy的专栏 2601

第28节:cesium 加载高程数据(含源码+视频)

cesium 加载高程(地形)数据

qq_29384639的博客 1740

Spring Boot 中的 RestTemplate

文章目录RestTemplate 访问 Web 资源请求方式GET 请求POST 请求PUT 请求DELETE 请求RestTemplate 高阶用法构造 URI传递 HTTP Header类型转换解析泛型对象定制 Rest TemplateRest Teamplate 支持的 HTTP 库通用接口默认实现第三方实现优化底层请求策略连接管理超时设置SSL 校验自定义配置示例【使用 httpcomp...

CHENFU_ZKK的博客 926

基于simulink 的不间断电源ups的项目实例

UPS系统的核心组件包括整流器、逆变器、电池管理系统和控制系统。- **Three-Phase Controlled Rectifier**:设置触发角为0度,用于控制整流器的输出电压。- **Three-Phase Inverter**:设置逆变器的输出频率为60Hz,用于将直流电转换为交流电。- **Control System**:编写MATLAB函数,用于监测市电状态并控制各模块的工作模式。- **Step**:设置阶跃时间,例如0.05秒,阶跃前后的值分别为0和1,用于模拟市电中断。

xiaoheshang_123的博客 708

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Spring Boot教程之十二: Spring – RestTemplate

要与 REST 交互,客户端需要创建客户端实例和请求对象、执行请求、解释响应、将响应映射到域对象以及处理异常。发送 HTTP GET 请求,返回包含从响应主体映射的对象的 ResponseEntity。将数据 POST 到 URL,返回包含从响应主体映射的对象的 ResponseEntity。对 URL 执行指定的 HTTP 方法,返回包含对象的 ResponseEntity。针对 URL 执行指定的 HTTP 方法,返回从响应主体映射的对象。发送 HTTP GET 请求,返回从响应主体映射的对象。

潜洋的专栏 2845

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Spring boot 之 RestTemplate访问

本文主要向大家介绍了 RestTemplate 这样一个 HTTP 请求工具类的常见用法,并没有涉及到源码,其实内部源码很多很深,包括和解析url模板,绑定参数的UriBuilderFactory UriTemplateHandler等等,建议跟踪源码跑一遍会更加理解restTemplate。**注意:**postForLocation方法返回的URI实际上是指响应头的Location字段,所以,请求的接口的响应头必须要有Location字段(即请求的接口实际上是一个重定向的接口),否则返回值为null。.

ceshiren456的博客 536

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

掌握 Spring Boot 中的 WebClient:何时以及为何使用它而不是 RestTemplate

WebClient 是一款功能强大、用途广泛且现代化的 Spring Boot 应用程序 HTTP 客户端,可帮助开发人员构建高效、反应灵敏且可扩展的系统。许多较旧的应用程序是在 WebClient 出现之前构建的,并且严重依赖 RestTemplate。则是现代、可扩展且反应灵敏的 Spring Boot 应用程序的首选。它提供了一种与 Web 服务交互的更有效方式,尤其是在需要高并发性和低延迟的场景中。仍然是许多 Spring Boot 应用程序中广泛使用的选项,尤其是在传统的同步架构中。

adminmail的博客 2905

spring boot 注入 restTemplate

转载自:http://blog.csdn.net/liuchuanhong1/article/details/54631080 package com.chhliu.springboot.restful; import org.springframework.beans.factory.annotation.Autowired; import org...

weixin_30460489的博客 587

spring boot 中 WebClient 与 RestTemplate 的对比总结

spring boot 中 WebClient 与 RestTemplate 的对比总结

爱的叹息的专栏 943
上一篇: Spring boot 数据库连接池
下一篇: spring微服务全家桶基础入门学习指南
xiaoduup
博客等级 码龄9年 23粉丝 83原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值