当前位置: 首页 > news >正文

springboot配置并使用RestTemplate

目录

一、RestTemplate配置

1、将RestTemplate初始化为Bean

2、使用HttpClient作为RestTemplate客户端

(1)引入HttpClient依赖

(2)修改RestTemplate配置类

3、设置拦截器

(1)新增拦截器类

(2)设置拦截器

4、新增支持的媒体类型

二、RestTemplate使用

1、RestTemplate注入

2、无参数get请求测试

(1)Controller代码

(2)RestTemplate单元测试

3、带参get请求测试

(1)Controller代码

(2)RestTemplate单元测试

4、带占位符参数的get请求测试

(1)Controller代码

(2)RestTemplate单元测试

5、post请求测试

(1)Article实体类

(2)Controller代码

(3)RestTemplate单元测试

6、设置请求头

(1)Article实体类

(2)Controller代码

(3)RestTemplate单元测试

7、上传文件

(1)Controller代码

(2)RestTemplate单元测试

8、文件下载

(1)Controller代码

(2)RestTemplate单元测试

三、参考


一、RestTemplate配置

1、将RestTemplate初始化为Bean

package com.xiaobai.conf;import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;import java.util.Collections;/*** @Author 王天文* @Date 2024/12/29 18:06* @Description: RestTemplate配置类*/
@Configuration
public class RestTemplateConf {/*** 当指定类型Bean不存在时,会创建一个新的Bean,如果用户自定义了Bean,将使用用户自定义的Bean* @return*/@ConditionalOnMissingBean(RestTemplate.class)@Beanpublic RestTemplate restTemplate() {// 使用JDK自带的HttpURLConnection作为客户端RestTemplate restTemplate = new RestTemplate();return restTemplate;}
}

2、使用HttpClient作为RestTemplate客户端

(1)引入HttpClient依赖

        <!--httpclient--><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.7</version></dependency>

(2)修改RestTemplate配置类

package com.xiaobai.conf;import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;import java.util.Collections;/*** @Author 王天文* @Date 2024/12/29 18:06* @Description: RestTemplate配置类*/
@Configuration
public class RestTemplateConf {/*** 当指定类型Bean不存在时,会创建一个新的Bean,如果用户自定义了Bean,将使用用户自定义的Bean* @return*/@ConditionalOnMissingBean(RestTemplate.class)@Beanpublic RestTemplate restTemplate() {// 使用httpclient作为底层客户端RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());return restTemplate;}/*** 使用httpclient作为底层客户端* @return*/@Beanpublic ClientHttpRequestFactory getClientHttpRequestFactory() {int timeout = 50000;RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build();CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();return new HttpComponentsClientHttpRequestFactory(httpClient);}
}

3、设置拦截器

(1)新增拦截器类

package com.xiaobai.conf;import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;import java.io.IOException;/*** @Author 王天文* @Date 2024/12/22 21:51* @Description: restTemplate拦截器*/
public class RestTemplateInterceptor implements ClientHttpRequestInterceptor {@Overridepublic ClientHttpResponse intercept(HttpRequest httpRequest,byte[] bytes,ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {ClientHttpResponse httpResponse = clientHttpRequestExecution.execute(httpRequest, bytes);return httpResponse;}
}

(2)设置拦截器

package com.xiaobai.conf;import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;import java.util.Collections;/*** @Author 王天文* @Date 2024/12/29 18:06* @Description: RestTemplate配置类*/
@Configuration
public class RestTemplateConf {/*** 当指定类型Bean不存在时,会创建一个新的Bean,如果用户自定义了Bean,将使用用户自定义的Bean* @return*/@ConditionalOnMissingBean(RestTemplate.class)@Beanpublic RestTemplate restTemplate() {// 使用JDK自带的HttpURLConnection作为客户端RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());// 设置拦截器restTemplate.setInterceptors(Collections.singletonList(restTemplateInterceptor()));return restTemplate;}/*** 使用httpclient作为底层客户端* @return*/@Beanpublic ClientHttpRequestFactory getClientHttpRequestFactory() {int timeout = 50000;RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build();CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();return new HttpComponentsClientHttpRequestFactory(httpClient);}/*** 拦截器* @return*/@Beanpublic RestTemplateInterceptor restTemplateInterceptor() {return new RestTemplateInterceptor();}
}

4、新增支持的媒体类型

RestTemplate 只支持application/json格式,需要手动补充text/plan,text/html格式

package com.xiaobai.conf;import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;import java.util.Arrays;
import java.util.Collections;/*** @Author 王天文* @Date 2024/12/29 18:06* @Description: RestTemplate配置类*/
@Configuration
public class RestTemplateConf {/*** 当指定类型Bean不存在时,会创建一个新的Bean,如果用户自定义了Bean,将使用用户自定义的Bean* @return*/@ConditionalOnMissingBean(RestTemplate.class)@Beanpublic RestTemplate restTemplate() {// 使用JDK自带的HttpURLConnection作为客户端RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());// 设置拦截器restTemplate.setInterceptors(Collections.singletonList(restTemplateInterceptor()));// 增加支持的媒体类型restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter());return restTemplate;}/*** 使用httpclient作为底层客户端* @return*/@Beanpublic ClientHttpRequestFactory getClientHttpRequestFactory() {int timeout = 50000;RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build();CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();return new HttpComponentsClientHttpRequestFactory(httpClient);}/*** 拦截器* @return*/@Beanpublic RestTemplateInterceptor restTemplateInterceptor() {return new RestTemplateInterceptor();}/*** 媒体类型* @return*/@Beanpublic MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {// RestTemplate 只支持application/json格式,需要手动补充text/html格式MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.TEXT_HTML));return mappingJackson2HttpMessageConverter;}
}

二、RestTemplate使用

1、RestTemplate注入

    @Autowiredprivate RestTemplate restTemplate;

2、无参数get请求测试

(1)Controller代码

    @GetMapping(value = "/getString")public String getString() {return "操作成功";}

(2)RestTemplate单元测试

    @Testpublic void testGetString() {ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:8090/getString", String.class);log.info(responseEntity.getBody());}

3、带参get请求测试

(1)Controller代码

    @GetMapping("/getRequestByParam")public Map<String, Object> getRequestByParam(@RequestParam("name") String name) {log.info("名称:" + name);Map<String, Object> map = new HashMap<>();map.put("responseData", "请求成功");return map;}

(2)RestTemplate单元测试

    @Testpublic void testParamGet() throws Exception {Map<String, Object> param = new HashMap<>();param.put("name", "张三");ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:8090/getRequestByParam?name={name}", String.class, param);log.info("响应信息:{}", responseEntity.getBody());}

4、带占位符参数的get请求测试

(1)Controller代码

    @GetMapping("/getRequestByPlaceHolder/{name}/{age}")public Map<String, Object> getRequestByPlaceHolder(@PathVariable("name") String name,@PathVariable("age") String age) {log.info("名称:" + name);log.info("年龄:" + age);Map<String, Object> map = new HashMap<>();map.put("responseData", "请求成功");return map;}

(2)RestTemplate单元测试

    @Testpublic void testPlaceholderGet() {ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:8090/getRequestByPlaceHolder/{1}/{2}", String.class, "张三", "25");log.info("响应信息:{}", responseEntity.getBody());}

5、post请求测试

(1)Article实体类

package com.xiaobai.aroundtest.entity;import lombok.Data;import java.io.Serializable;/*** @author wangtw* @date 2023/12/6 0:35* @description*/
@Data
public class Article implements Serializable {private static final long serialVersionUID = 1L;/*** 文章名称*/private String name;/*** 描述*/private String description;
}

(2)Controller代码

    @PostMapping("/postRequest")public Map<String, Object> postRequest(@RequestParam String name, @RequestBody Article article) {log.info("名称:" + name);log.info("文章名称:" + article.getName());log.info("文章描述:" + article.getDescription());Map<String, Object> map = new HashMap<>();map.put("responseData", "请求成功");return map;}

(3)RestTemplate单元测试

    @Testpublic void testPost() {// 表单数据Map<String, Object> formData = new HashMap<>();formData.put("name", "解忧杂货店");formData.put("description", "这是一本好书");// 单独传参Map<String, Object> param = new HashMap<>();param.put("name", "东野圭吾");// 请求调用HttpEntity<Map<String, Object>> formEntity = new HttpEntity<>(formData);ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://localhost:8090/postRequest?name={name}", formEntity, String.class, param);log.info("响应信息:{}", responseEntity.getBody());}

6、设置请求头

(1)Article实体类

package com.xiaobai.aroundtest.entity;import lombok.Data;import java.io.Serializable;/*** @author wangtw* @date 2023/12/6 0:35* @description*/
@Data
public class Article implements Serializable {private static final long serialVersionUID = 1L;/*** 文章名称*/private String name;/*** 描述*/private String description;
}

(2)Controller代码

    @PostMapping("/postRequestHeader")public Map<String, Object> postRequestHeader(HttpServletRequest request,@RequestParam String name, @RequestBody Article article) {String token = request.getHeader("token");log.info("请求token:" + token);log.info("名称:" + name);log.info("文章名称:" + article.getName());log.info("文章描述:" + article.getDescription());Map<String, Object> map = new HashMap<>();map.put("responseData", "请求成功");return map;}

(3)RestTemplate单元测试

    @Testpublic void testPostHeader() {// 请求头HttpHeaders httpHeaders = new HttpHeaders();httpHeaders.add("token", "123456");// 表单数据Map<String, Object> formData = new HashMap<>();formData.put("name", "解忧杂货店");formData.put("description", "这是一本好书");// 单独传参Map<String, Object> param = new HashMap<>();param.put("name", "东野圭吾");// 请求调用HttpEntity<Map<String, Object>> formEntity = new HttpEntity<>(formData, httpHeaders);ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://localhost:8090/postRequestHeader?name={name}", formEntity, String.class, param);log.info("响应信息:{}", responseEntity.getBody());}

7、上传文件

(1)Controller代码

    @PostMapping("/upload")public Map<String, Object> upload(@RequestParam String name, MultipartFile uploadFile) throws IOException {log.info("名称:" + name);uploadFile.transferTo(new File("D:\\temp/" + uploadFile.getOriginalFilename()));Map<String, Object> map = new HashMap<>();map.put("responseData", "请求成功");return map;}

(2)RestTemplate单元测试

    @Testpublic void testUploadFile() {MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();param.add("uploadFile", new FileSystemResource(new File("D:\\christmas-tree.svg")));param.add("name", "张三");// 请求头设置HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.MULTIPART_FORM_DATA);// 请求调用HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(param, headers);ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://localhost:8090/upload", formEntity, String.class);log.info("响应信息:{}", responseEntity.getBody());}

8、文件下载

(1)Controller代码

    @PostMapping("/download")public Map<String, Object> download(@RequestParam String fileName,HttpServletResponse response) {log.info("文件名称:" + fileName);File file = new File("D:\\temp/" + fileName);try(FileInputStream fileInputStream = new FileInputStream(file);ServletOutputStream outputStream = response.getOutputStream()) {response.setHeader("content-disposition","attachment;fileName=" + URLEncoder.encode(fileName,"UTF-8"));FileCopyUtils.copy(fileInputStream, outputStream);} catch (Exception e) {e.printStackTrace();}Map<String, Object> map = new HashMap<>();map.put("responseData", "请求成功");return map;}

(2)RestTemplate单元测试

    @Testpublic void testDownloadFile() {MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();param.add("fileName", "christmas-tree.svg");// 请求调用HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(param);ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity("http://localhost:8090/download", formEntity, byte[].class);// 获取响应头HttpHeaders responseEntityHeaders = responseEntity.getHeaders();Set<Map.Entry<String, List<String>>> responseSet = responseEntityHeaders.entrySet();for (Map.Entry<String, List<String>> responseValue : responseSet) {log.info("响应头:" + responseValue.getKey() + ",响应内容:" + responseValue.getValue());}try {// 文件保存byte[] fileData = responseEntity.getBody();FileCopyUtils.copy(fileData, new File("D:\\christmas-tree1.svg"));} catch (IOException e) {e.printStackTrace();}}

三、参考

Spring之RestTemplate详解

相关文章:

springboot配置并使用RestTemplate

目录 一、RestTemplate配置 1、将RestTemplate初始化为Bean 2、使用HttpClient作为RestTemplate客户端 &#xff08;1&#xff09;引入HttpClient依赖 &#xff08;2&#xff09;修改RestTemplate配置类 3、设置拦截器 &#xff08;1&#xff09;新增拦截器类 &#xf…...

人工智能-Python网络编程-TCP

1 TCP-概念版 服务端 import socket ​ # 1 创建服务端套接字对象 # socket.AF_INET IPV4 # socket.SOCK_STREAM TCP # socket.SOCK_DGRAM UDP tcp_server_socket socket.socket(socket.AF_INET, socket.SOCK_STREAM) ​ # 2 绑定端口号 tcp_server_socket.bind((192.…...

【Java回顾】Day3 继承|Override/Ovverload|多态|抽象类|封装|接口|枚举

学习资料 菜鸟教程 https://www.runoob.com/java/java-interfaces.html 继承|Override/Ovverload|多态|抽象类|封装|接口|枚举 继承 创建分等级层次的类&#xff0c;子类继承父类的特征、行为、方法 class 父类{ } class 子类 extends 父类{ super(); }一些性质 Java 不支持…...

SpringMVC(四)响应

目录 数据处理及跳转 1. 结果跳转方式 ①.ModelAndView ②.ServletAPI 1、通过HttpServletResponse进行输出 2、通过HttpServletResponse实现请求转发 3、通过HttpServletResponse实现重定向 ③.SpringMVC 1.直接输出 2.请求转发 3.重定向 2.ResponseBody响应json数…...

vim 的基础使用

目录 一&#xff1a;vim 介绍二&#xff1a;vim 特点三&#xff1a;vim 配置四&#xff1a;vim 使用1、vim 语法格式2、vim 普通模式&#xff08;1&#xff09;保存退出&#xff08;2&#xff09;光标跳转&#xff08;3&#xff09;文本删除&#xff08;4&#xff09;文本查找&…...

关于flinkCDC监控mysql binlog时,datetime类型自动转换成时间戳类型问题

flinkCDC监控mysql binlog时&#xff0c;datetime类型自动转换成时间戳类型 问题解决1.自定义转换器类2.代码引用 结果 问题 flink版本&#xff1a;1.18.1&#xff0c;mysql版本&#xff1a;8.0.40 使用FlinkCDC的MySqlSource 连接mysql&#xff0c;对于datetime 类型字段&…...

基于Springboot校园失物招领系统【附源码】

基于Springboot校园失物招领系统 效果如下&#xff1a; 系统登陆页面 物品页面 系统首页面 失物招领管理页面 失物认领页面 宣传视频页面 物品挂失留言管理页面 宣传视频类型管理页面 研究背景 在校园环境中&#xff0c;失物招领是一个常见的问题。传统的失物招领方式主要依…...

单片机端口操作和独立引脚操作

单片机端口操作和独立引脚操作 在单片机编程中&#xff0c;控制I/O端口是最基础的操作之一。通过控制端口&#xff0c;我们可以实现对外设&#xff08;如LED、按键、继电器等&#xff09;的控制。在51单片机中&#xff0c;有两种常见的端口操作方式&#xff1a;整体控制&#…...

【Vim Masterclass 笔记03】S03L10 + S03L11:Vim 中的文本删除操作以及 Vim 思维习惯的培养(含 DIY 拓展知识点)

文章目录 Section 3&#xff1a;Vim Essentials&#xff08;Vim 核心知识&#xff09;S03L10 Vim 核心浏览命令同步练习点评课S03L11 Deleting Text and "Thinking in Vim" 文本的删除及 Vim 思维习惯的培养1 删除单个字符2 删除一个单词2.1 推广1&#xff1a;D HJK…...

ARM200~500部署

前提&#xff1a;数据库已经安装好&#xff0c;并且正常运行 1.修改hostname,将里面的AR-A 改为hzx vi /etc/hostname 2.重启网络服务 sudo systemctl restart NetworkManager 3.修改community-admin.service 文件&#xff0c;更改小区名称和IP&#xff0c;并将文件上传到/…...

word中插入zotero引用

1、参考文献末尾没有文献&#xff1f; 在文献条目要显示的地方点击“refresh” 2、参考文献条目没有悬挂缩进&#xff1f; 把“书目”添加到样式库中&#xff0c;修改样式为悬挂缩进1.5字符 3、交叉引用&#xff1f; 宏 新建一个宏 粘贴下面代码 Public Sub ZoteroLinkCita…...

需求上线,为什么要刷缓存?

在需求上线的过程中&#xff0c;刷缓存主要有以下几个重要原因&#xff1a; 一、保证数据的准确性 旧数据残留问题 缓存是为了加快数据访问速度而存储的数据副本。在需求更新后&#xff0c;之前缓存中的数据可能已经不符合新的业务逻辑。例如&#xff0c;一个电商网站修改了商…...

TVS二极管选型【EMC】

TVS器件并联在电路中&#xff0c;当电路正常工作时&#xff0c;他处于截止状态&#xff08;高阻态&#xff09;&#xff0c;不影响线路正常工作&#xff0c;当线路处于异常过压并达到其击穿电压时&#xff0c;他迅速由高阻态变为低阻态&#xff0c;给瞬间电流提供一个低阻抗导通…...

《从入门到精通:蓝桥杯编程大赛知识点全攻略》(一)-递归实现指数型枚举、递归实现排列型枚举

本篇博客将聚焦于通过递归来实现两种经典的枚举方法&#xff1a;指数型枚举和排列型枚举。这两种枚举方式在计算机科学和算法竞赛中都有广泛应用&#xff0c;无论是在解题中&#xff0c;还是在实际工作中都极具价值。 目录 前言 斐波那契数列递归 递归实现指数型枚举 算法思…...

C#对线程同步的应用

什么是线程同步&#xff1f;线程同步的应用场景有哪些&#xff1f;在C#中有哪些线程同步方式&#xff1f;下面对这些问题做一个总结&#xff0c;让大家在面试的时候遇到这些问题能够游刃有余。 线程同步是指在多线程环境下&#xff0c;多个线程同时访问共享资源时&#xff0c;确…...

基于微信小程序的面部动作检测系统

引言 本技术文档旨在详细阐述一个基于微信小程序的面部动作检测系统的技术路线、实现方法及关键技术框架。系统的核心功能包括检测用户的左右转头、眨眼和张嘴动作&#xff0c;并根据检测结果逐步引导用户完成任务。为确保系统的安全性和准确性&#xff0c;特别是防止用户通过…...

Activation Functions

Chapter4&#xff1a;Activation Functions 声明&#xff1a;本篇博客笔记来源于《Neural Networks from scratch in Python》&#xff0c;作者的youtube 其实关于神经网络的入门博主已经写过几篇了&#xff0c;这里就不再赘述&#xff0c;附上链接。 1.一文窥见神经网络 2.神经…...

《Vue3实战教程》37:Vue3生产部署

如果您有疑问&#xff0c;请观看视频教程《Vue3实战教程》 生产部署​ 开发环境 vs. 生产环境​ 在开发过程中&#xff0c;Vue 提供了许多功能来提升开发体验&#xff1a; 对常见错误和隐患的警告对组件 props / 自定义事件的校验响应性调试钩子开发工具集成 然而&#xff…...

Linux:各发行版及其包管理工具

相关阅读 Linuxhttps://blog.csdn.net/weixin_45791458/category_12234591.html?spm1001.2014.3001.5482 Debian 包管理工具&#xff1a;dpkg&#xff08;低级包管理器&#xff09;、apt&#xff08;高级包管理器&#xff0c;建立在dpkg基础上&#xff09;包格式&#xff1a;…...

【计算机网络】课程 作业一 搭建连续覆盖的办公网络

作业一 搭建连续覆盖的办公网络 题目&#xff1a;论述题&#xff08;共1题&#xff0c;100分&#xff09; 充分利用所学习的数据链路层局域网知识&#xff0c;加上物理层的基础知识&#xff0c;请给一个办公场所&#xff08;三层&#xff0c;每层约100平方&#xff09;&#xf…...

解锁数据库简洁之道:FastAPI与SQLModel实战指南

在构建现代Web应用程序时&#xff0c;与数据库的交互无疑是核心环节。虽然传统的数据库操作方式&#xff08;如直接编写SQL语句与psycopg2交互&#xff09;赋予了我们精细的控制权&#xff0c;但在面对日益复杂的业务逻辑和快速迭代的需求时&#xff0c;这种方式的开发效率和可…...

基于Docker Compose部署Java微服务项目

一. 创建根项目 根项目&#xff08;父项目&#xff09;主要用于依赖管理 一些需要注意的点&#xff1a; 打包方式需要为 pom<modules>里需要注册子模块不要引入maven的打包插件&#xff0c;否则打包时会出问题 <?xml version"1.0" encoding"UTF-8…...

WordPress插件:AI多语言写作与智能配图、免费AI模型、SEO文章生成

厌倦手动写WordPress文章&#xff1f;AI自动生成&#xff0c;效率提升10倍&#xff01; 支持多语言、自动配图、定时发布&#xff0c;让内容创作更轻松&#xff01; AI内容生成 → 不想每天写文章&#xff1f;AI一键生成高质量内容&#xff01;多语言支持 → 跨境电商必备&am…...

第 86 场周赛:矩阵中的幻方、钥匙和房间、将数组拆分成斐波那契序列、猜猜这个单词

Q1、[中等] 矩阵中的幻方 1、题目描述 3 x 3 的幻方是一个填充有 从 1 到 9 的不同数字的 3 x 3 矩阵&#xff0c;其中每行&#xff0c;每列以及两条对角线上的各数之和都相等。 给定一个由整数组成的row x col 的 grid&#xff0c;其中有多少个 3 3 的 “幻方” 子矩阵&am…...

Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)

参考官方文档&#xff1a;https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java&#xff08;供 Kotlin 使用&#xff09; 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...

GC1808高性能24位立体声音频ADC芯片解析

1. 芯片概述 GC1808是一款24位立体声音频模数转换器&#xff08;ADC&#xff09;&#xff0c;支持8kHz~96kHz采样率&#xff0c;集成Δ-Σ调制器、数字抗混叠滤波器和高通滤波器&#xff0c;适用于高保真音频采集场景。 2. 核心特性 高精度&#xff1a;24位分辨率&#xff0c…...

C/C++ 中附加包含目录、附加库目录与附加依赖项详解

在 C/C 编程的编译和链接过程中&#xff0c;附加包含目录、附加库目录和附加依赖项是三个至关重要的设置&#xff0c;它们相互配合&#xff0c;确保程序能够正确引用外部资源并顺利构建。虽然在学习过程中&#xff0c;这些概念容易让人混淆&#xff0c;但深入理解它们的作用和联…...

【C++进阶篇】智能指针

C内存管理终极指南&#xff1a;智能指针从入门到源码剖析 一. 智能指针1.1 auto_ptr1.2 unique_ptr1.3 shared_ptr1.4 make_shared 二. 原理三. shared_ptr循环引用问题三. 线程安全问题四. 内存泄漏4.1 什么是内存泄漏4.2 危害4.3 避免内存泄漏 五. 最后 一. 智能指针 智能指…...

并发编程 - go版

1.并发编程基础概念 进程和线程 A. 进程是程序在操作系统中的一次执行过程&#xff0c;系统进行资源分配和调度的一个独立单位。B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。C.一个进程可以创建和撤销多个线程;同一个进程中…...

Vite中定义@软链接

在webpack中可以直接通过符号表示src路径&#xff0c;但是vite中默认不可以。 如何实现&#xff1a; vite中提供了resolve.alias&#xff1a;通过别名在指向一个具体的路径 在vite.config.js中 import { join } from pathexport default defineConfig({plugins: [vue()],//…...