【接口设计】学会用 RestTemplate 发请求

接口设计》系列,共包含以下 5 篇文章:

  • 前后端的通信方式 REST
  • 如何设计统一 RESTful 风格的数据接口
  • 为 APP、PC、H5 网页提供统一风格的 API(实战篇,附源码地址)
  • 用 Swagger 实现接口文档
  • 学会用 RestTemplate 发请求

😊 如果您觉得这篇文章有用 ✔️ 的话,请给博主一个一键三连 🚀🚀🚀 吧 (点赞 🧡、关注 💛、收藏 💚)!!!您的支持 💖💖💖 将激励 🔥 博主输出更多优质内容!!!

学会用 RestTemplate 发请求

  • 1.认识 RestTemplate
  • 2.创建测试实体
  • 3.创建用于测试的 API
  • 4.用 RestTemplate 发送 GET 请求
    • 4.1 方法一:使用 getForEntity
      • 4.1.1 返回 String(不带参数)
      • 4.1.2 返回 String(带参数)
      • 4.1.3 返回对象
    • 4.2 方法二:使用 getForObject
    • 4.3 本小节完整代码
  • 5.用 RestTemplate 发送 POST 请求
    • 5.1 方法一:使用 postForEntity
    • 5.2 方法二:使用 postForObject
    • 5.3 方法三:使用 postForLocation
    • 5.4 方法四:使用 exchange
    • 5.5 本小节完整代码
  • 6.用 RestTemplate 发送 PUT 和 DELETE 请求
    • 6.1 PUT 请求
    • 6.2 DELETE 请求
    • 6.3 本小节完整代码

1.认识 RestTemplate

在 Java 应用程序中访问 RESTful 服务,可以使用 Apache 的 HttpClient 来实现。不过此方法使用起来太烦琐。 Spring 提供了一种简单便捷的模板类 —— RestTemplate 来进行操作。RestTemplate 是 Spring 提供的用于访问 REST 服务的客户端,它提供了多种便捷访问远程 HTTP 服务的方法,能够大大提高客户端的编写效率。

RestTemplate 用于同步 Client 端的核心类,简化与 HTTP 服务的通信。在默认情况下, RestTemplate 默认依赖 JDK 的 HTTP 连接工具。也可以通过 setRequestFactory 属性切换到不同的 HTTP 源,比如 Apache HttpComponents、Netty 和 OkHttp。

RestTemplate 简化了提交表单数据的难度,并附带自动转换为 JSON 格式数据的功能。该类的入口主要是根据 HTTP 的 6 种方法制定的。

HTTP 方法RestTemplate 方法HTTP 方法RestTemplate 方法
DELETEdeletePOSTpostForLocation
GETgetForObjectPOSTpostForObject
GETgetForEntityPUTput
HEADheadForHeadersanyexchange
OPTIONSoptionsForAllowanyexecute

此外,exchangeexcute 也可以使用上述方法。

RestTemplate 默认使用 HttpMessageConverter 将 HTTP 消息转换成 POJO,或从 POJO 转换成 HTTP 消息,默认情况下会注册主 MIME 类型的转换器,但也可以通过 setMessageConverters 注册其他类型的转换器。

2.创建测试实体

package com.example.demo.entity;public class User {private long id;private String name;public User() {}public User(long id, String name) {this.id = id;this.name = name;}public long getId() {return id;}public void setId(long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}}

3.创建用于测试的 API

@RestController
public class TestController {@RequestMapping(value = "/getparameter", method = RequestMethod.GET)public User getparameter(User user) {return user;}@RequestMapping(value = "/getuser1", method = RequestMethod.GET)public User user1() {return new User(1, "Bob");}@RequestMapping(value = "/postuser", method = RequestMethod.POST)public User postUser(User user) {System.out.println("name:" + user.getName());System.out.println("id:" + user.getId());return user;}@ResponseBody@RequestMapping(path = "success")public String loginSuccess(String name, Integer id) {return "welcome " + name;}@RequestMapping(value = "/post", method = RequestMethod.POST)public String post(HttpServletRequest request, @RequestParam(value = "name", required = false) String name,@RequestParam(value = "password", required = false) String password, @RequestParam(value = "id", required = false) Integer id, HttpServletResponse response) {// 如果获取的值为 “null”,则需要把 URI 添加到 response 信息的 header 中。添加方法为:“response.addHeader("Location",uri)”response.addHeader("Location", "success?name=" + name + "&id=" + id + "&status=success");return "redirect:/success?name=" + name + "&id=" + id + "&status=success";// return "redirect:/success?name=" + URLEncoder.encode(name, "UTF-8") + "&id=" + id + "&status=success";}
}

4.用 RestTemplate 发送 GET 请求

在 RestTemplate 中发送 GET 请求,可以通过 getForEntitygetForObject 两种方式。

下面具体实现用 RestTemplate 发送 GET 请求。

4.1 方法一:使用 getForEntity

4.1.1 返回 String(不带参数)

@RequestMapping("/nparameters")
// 返回 String, 不带参数
public String nparameters() {RestTemplate client = restTemplateBuilder.build();ResponseEntity<String> responseEntity = client.getForEntity("http://localhost:8080/getuser1", String.class);return responseEntity.getBody();
}

在这里插入图片描述

4.1.2 返回 String(带参数)

在调用服务提供者提供的接口时,有时需要传递参数,有以下两种不同的方式。

① 用一个数字做占位符。最后是一个可变长度的参数,用来替换前面的占位符。使用方法见以下代码:

@RequestMapping("/withparameters1")
// 返回 String, 带参数
public String withparameters1() {RestTemplate client = restTemplateBuilder.build();ResponseEntity<String> responseEntity = client.getForEntity("http://localhost:8080/getparameter?name={1}&id={2}", String.class, "Mike", 2);return responseEntity.getBody();
}

在这里插入图片描述

② 使用 name={name} 这种形式。最后一个参数是一个 mapmapkey 即为前边占位符的名字,mapvalue 为参数值。使用方法见以下代码:

@RequestMapping("/withparameters2")
// 返回 String, 带参数
public String withparameters2() {RestTemplate client = restTemplateBuilder.build();Map<String, String> map = new HashMap<>();map.put("name", "Tony");ResponseEntity<String> responseEntity = client.getForEntity("http://localhost:8080/getparameter?name={name}&id=3", String.class, map);return responseEntity.getBody();
}

在这里插入图片描述

4.1.3 返回对象

@RequestMapping("/user1")
// 返回一个自定义类型的对象
public User restUser1() {RestTemplate client = restTemplateBuilder.build();ResponseEntity<User> responseEntity = client.getForEntity("http://localhost:8080/getuser1", User.class);return responseEntity.getBody();
}

在这里插入图片描述

4.2 方法二:使用 getForObject

getForObject 函数是对 getForEntity 函数的进一步封装。如果你只关注返回的消息体的内容,对其他信息都不关注,则可以使用 getForObject,见以下代码:

@RequestMapping("/getforobject")
public User getForObject() {RestTemplate client = restTemplateBuilder.build();User user = client.getForObject("http://localhost:8080/getuser1", User.class);return user;
}

在这里插入图片描述

4.3 本小节完整代码

package com.example.demo.controller;import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;import java.util.HashMap;
import java.util.Map;@RestController
public class GetController {@AutowiredRestTemplateBuilder restTemplateBuilder;@RequestMapping("/nparameters")//返回String,不带参数public String nparameters() {RestTemplate client = restTemplateBuilder.build();ResponseEntity<String> responseEntity = client.getForEntity("http://localhost:8080/getuser1", String.class);return responseEntity.getBody();}@RequestMapping("/withparameters1")//返回String,带参数public String withparameters1() {RestTemplate client = restTemplateBuilder.build();ResponseEntity<String> responseEntity = client.getForEntity("http://localhost:8080/getparameter?name={1}&id={2}", String.class, "Mike", 2);return responseEntity.getBody();}@RequestMapping("/withparameters2")//返回String,带参数public String withparameters2() {RestTemplate client = restTemplateBuilder.build();Map<String, String> map = new HashMap<>();map.put("name", "Tony");ResponseEntity<String> responseEntity = client.getForEntity("http://localhost:8080/getparameter?name={name}&id=3", String.class, map);return responseEntity.getBody();}@RequestMapping("/user1")//返回一个自定义类型的对象public User restUser1() {RestTemplate client = restTemplateBuilder.build();ResponseEntity<User> responseEntity = client.getForEntity("http://localhost:8080/getuser1", User.class);return responseEntity.getBody();}@RequestMapping("/getforobject")public User getForObject() {RestTemplate client = restTemplateBuilder.build();User user = client.getForObject("http://localhost:8080/getuser1", User.class);return user;}
}

5.用 RestTemplate 发送 POST 请求

在 RestTemplate 中,POST 请求可以通过 postForEntitypostForObjectpostForLocationexchange 四种方法来发起。

postForEntitypostForObjectpostForLocation 三种方法传递参数时,Map 不能被定义为 HashMap、LinkedHashMap,而应被定义为 LinkedMultiValueMap,这样参数才能成功传递到后台。

5.1 方法一:使用 postForEntity

  • postForEntity(String url, Object request, Class responseType, Object ... urlVariables)
  • postForEntity(String url, Object request, Class responseType, Map urlVariables)
  • postForEntity(String url, Object request, Class responseType)

第 1 个参数表示 要调用的服务的地址。第 2 个参数表示 上传的参数。第 3 个参数表示 返回的消息体的数据类型

@GetMapping("/postForEntity")
public User postForEntity() {// RestTemplate client = restTemplateBuilder.build();// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);User user = new User();user.setName("pipi");user.setId(4);// 方法的第一参数表示要调用的服务的地址// 方法的第二个参数表示上传的参数// 方法的第三个参数表示返回的消息体的数据类型ResponseEntity<User> responseEntity = restTemplate.postForEntity("http://localhost:8080/postuser", paramMap, User.class);return responseEntity.getBody();
}
  • MultiValueMap:封装参数,千万不要替换为 Map 与 HashMap,否则参数无法被传递。
  • restTemplate.postForEntity("url", paramMap, User.class):参数分别表示要调用的服务的地址、上传的参数、返回的消息体的数据类型。

在这里插入图片描述

5.2 方法二:使用 postForObject

  • postForObject(String url, Object request, Class responseType, Object ... urlVariables)
  • postForObject(String url, Object request, Class responseType, Map urlVariables)
  • postForObject(String url, Object request, Class responseType)

postForObjectgetForObject 相对应,只关注返回的消息体,见以下代码:

@RequestMapping("/postForObject")
public String postForObject() {// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);RestTemplate client = restTemplateBuilder.build();User user = new User();user.setName("pipi");user.setId(5);String response = client.postForObject("http://localhost:8080/postuser", paramMap, String.class);return response;
}

在这里插入图片描述

5.3 方法三:使用 postForLocation

postForLocation 也用于提交资源。在提交成功之后,会返回新资源的 URI。它的参数和前面两种方法的参数基本一致,只不过 该方法的返回值为 URI,表示新资源的位置

postForLocation(String url, Object request, Object ... urlVariables)
postForLocation(String url, Object request, Map urlVariables)
postForLocation(String url, Object request)

它用于提交数据,并获取返回的 URI。一般登录、注册都是 POST 请求,操作完成之后,跳转到某个页面,这种场景就可以使用 postForLocation。所以,先要添加处理登录的 API,见以下代码:

@ResponseBody
@RequestMapping(path = "success")
public String loginSuccess(String name, Integer id) {return "welcome " + name;
}@RequestMapping(value = "/post", method = RequestMethod.POST)
public String post(HttpServletRequest request, @RequestParam(value = "name", required = false) String name,@RequestParam(value = "password", required = false) String password, @RequestParam(value = "id", required = false) Integer id, HttpServletResponse response) {// 如果获取的值为 “null”,则需要把 URI 添加到 response 信息的 header 中。添加方法为:“response.addHeader("Location",uri)”response.addHeader("Location", "success?name=" + name + "&id=" + id + "&status=success");return "redirect:/success?name=" + name + "&id=" + id + "&status=success";// return "redirect:/success?name=" + URLEncoder.encode(name, "UTF-8") + "&id=" + id + "&status=success";
}

然后使用 postForLocation 请求,用法见以下代码:

@RequestMapping("/postForLocation")
public URI postForLocation() {// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);RestTemplate client = restTemplateBuilder.build();User user = new User();user.setName("pipi");user.setId(6);URI response = client.postForLocation("http://localhost:8080/postuser", paramMap);return response;
}

在这里插入图片描述
在这里插入图片描述

如果有中文,则结果可能会出现乱码,可以用 URLEncoder.encode(name, "UTF-8") 进行处理。

如果获取的值为 null,则需要把 URI 添加到 response 信息的 header 中。添加方法为:response.add("Location",uri)

5.4 方法四:使用 exchange

使用 exchange 方法可以指定调用方式,使用方法如下:

ResponseEntity<String> response = template.exchange(newUrl, HttpMethod.DELETE, request, String.class);
@RequestMapping("/postForexchange")
public String postForexchange() {// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);RestTemplate client = restTemplateBuilder.build();HttpHeaders headers = new HttpHeaders();// headers.set("id", "long");HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);ResponseEntity<String> response = client.exchange("http://localhost:8080/postuser", HttpMethod.POST, httpEntity, String.class, paramMap);return response.getBody();
}

在这里插入图片描述

5.5 本小节完整代码

package com.example.demo.controller;import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;import java.net.URI;@RestController
public class PostController {@AutowiredRestTemplateBuilder restTemplateBuilder;RestTemplate restTemplate = new RestTemplate();@GetMapping("/postForEntity")public User postForEntity() {// RestTemplate client= restTemplateBuilder.build();// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);User user = new User();user.setName("pipi");user.setId(4);// 方法的第一参数表示要调用的服务的地址// 方法的第二个参数表示上传的参数// 方法的第三个参数表示返回的消息体的数据类型ResponseEntity<User> responseEntity = restTemplate.postForEntity("http://localhost:8080/postuser", paramMap, User.class);return responseEntity.getBody();}@RequestMapping("/postForObject")public String postForObject() {// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);RestTemplate client = restTemplateBuilder.build();User user = new User();user.setName("pipi");user.setId(5);String response = client.postForObject("http://localhost:8080/postuser", paramMap, String.class);return response;}@RequestMapping("/postForexchange")public String postForexchange() {// 封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();paramMap.add("name", "20240720");paramMap.add("id", 4);RestTemplate client = restTemplateBuilder.build();HttpHeaders headers = new HttpHeaders();// headers.set("id", "long");HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);ResponseEntity<String> response = client.exchange("http://localhost:8080/postuser", HttpMethod.POST, httpEntity, String.class, paramMap);return response.getBody();}

6.用 RestTemplate 发送 PUT 和 DELETE 请求

6.1 PUT 请求

在 RestTemplate 中,发送 修改 请求和前面介绍的 postForEntity 方法的参数基本一致,只是修改请求没有返回值,用法如下:

@RequestMapping("/put")
public void put() {RestTemplate client = restTemplateBuilder.build();User user = new User();user.setName("pipi");client.put("http://localhost:8080/{1}", user, 7);
}

最后的 7 用来替换前面的占位符 {1}

6.2 DELETE 请求

删除 请求,可以通过调用 DELETE 方法来实现,用法见以下代码:

@RequestMapping("/delete")
public void delete() {RestTemplate client = restTemplateBuilder.build();client.delete("http://localhost:8080/{1}", 8);
}

最后的 8 用来替换前面的占位符 {1}

6.3 本小节完整代码

package com.example.demo.controller;import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;import java.net.URI;@RestController
public class PutAndDeleteController {@AutowiredRestTemplateBuilder restTemplateBuilder;@RequestMapping("/put")public void put() {RestTemplate client = restTemplateBuilder.build();User user = new User();user.setName("hongwei");client.put("http://localhost:8080/{1}", user, 7);}@RequestMapping("/delete")public void delete() {RestTemplate client = restTemplateBuilder.build();client.delete("http://localhost:8080/{1}", 8);}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/3268220.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

【C++】选择结构案例-三目运算符

三目运算符语法格式&#xff1a; 布尔表达式?表达式1:表达式2 运算过程&#xff1a;如果布尔表达式的值为 true &#xff0c;则返回 表达式1 的值&#xff0c;否则返回 表达式2 的值 &#xff08;三目运算符指的是&#xff1f;和&#xff1a;&#xff09; 在这个三目运算符…

USB转多路串口-纯硬件实现串口数据传输指示灯电路

前言 串口相关产品往往要求有数据收发时LED闪烁&#xff0c;我们经常会用软件实现&#xff0c;在MCU内注册一个定时器&#xff0c;有数据发送时就闪烁一段时间。软件点灯这种方式存在两个缺陷&#xff0c;一是接收方向不好实现&#xff1b;二是定时器一般用固定频率&#xff0…

Redis的两种持久化方式---RDB、AOF

rdb其实就是一种快照持久化的方式&#xff0c;它会将Redis在某个时间点的所有的数据状态以二进制的方式保存到硬盘上的文件当中&#xff0c;它相对于aof文件会小很多&#xff0c;因为知识某个时间点的数据&#xff0c;当然&#xff0c;这就会导致它的实时性不够高&#xff0c;如…

Nature Electronics|柔性可吞服电子设备用于胃部电生理学监测(柔性健康监测/可吞服电子/柔性

美国麻省理工学院David H. Koch 综合癌症研究所的 Giovanni Traverso团队,在《Nature Electronics》上发布了一篇题为“An ingestible device for gastric electrophysiology”的论文。论文内容如下: 一、 摘要 从胃肠道和肠道神经系统记录高质量电生理数据的能力有助于了解…

信通院发布!首个大模型混合云标准

近日&#xff0c;中国信通院发布了首个大模型混合云标准&#xff0c;通过定位当前大模型混合云的能力水平&#xff0c;为基于混合云的大模型服务实践提供指引&#xff0c;并明确未来提升方向。同时&#xff0c;中国信通院基于标准展开大模型混合云能力成熟度专项测试&#xff0…

生信技能54 - WisecondorX多线程并行分析CNV

WisecondorX分析CNV,默认单样本分析,batch_analysis参数设置为True可启动多样本并行分析。 WisecondorX基本使用方法以及npz文件转换和reference构建参考文章: 生信技能53 - wiseconrdoX自动化批量npz转换和reference构建 github: https://github.com/CenterForMedicalGe…

Windows 安装 PostgreSQL 并安装 vector 扩展

目录 前言 下载安装 pgAdmin 4 vector 扩展 前言 调研大模型时&#xff0c;了解到一些大模型的应用&#xff0c;其中一个就是知识库&#xff0c;用户可以上传文档到知识库中&#xff0c;系统解析文档并将内容向量化保存起来&#xff0c;以便在和模型交互时使用。 在和大模…

【MySQL进阶之路 | 高级篇】数据操作类型的角度理解共享锁,排他锁

1. 从数据操作的类型划分&#xff1a;读锁&#xff0c;写锁 对于数据库并发事务的读-读情况并不会引起什么问题。对于写-写&#xff0c;读-写操作或写-写操作这些情况可能会引起一些问题&#xff0c;需要使用MVCC或者加锁的方式来解决它们。在使用加锁的方式解决问题时&#x…

photoshop学习笔记——选区3 快速选择工具

快速选择工具 W shift W 在3种快速选择工具之间切换 对象选择工具 photoshop CC中没有这个工具&#xff0c;利用AI&#xff0c;将款选中的对象快速的提取选区&#xff0c;测试了一下&#xff0c;选区制作的非常nice快速选择工具 跟磁性套索类似&#xff0c;自动识别颜色相似…

如何快速抓取小红书帖子评论?两大实战Python技巧揭秘

摘要&#xff1a; 本文将深入探讨两种高效的Python方法&#xff0c;助您迅速获取小红书文章下方的所有评论&#xff0c;提升市场分析与用户洞察力。通过实战示例与详细解析&#xff0c;让您轻松掌握数据抓取技巧&#xff0c;为您的内容营销策略提供有力支持。 如何快速抓取小…

C++ | Leetcode C++题解之第284题窥视迭代器

题目&#xff1a; 题解&#xff1a; template <class T> class PeekingIterator : public Iterator<T> { public:PeekingIterator(const vector<T>& nums) : Iterator<T>(nums) {flag Iterator<T>::hasNext();if (flag) {nextElement Ite…

[Unity] ShaderGraph实现不同贴图素材的同一材质球复用

无意间发现的ShaderGraph小技巧&#xff0c; 可以实现同一个ShaderGraph&#xff0c;同一个Material材质球&#xff0c; 但使用不同的Texture贴图&#xff0c;而Sprite显示不会相互覆盖。 具体实现方法如下&#xff1a; 声明Texture2D时&#xff0c;把名字命名成&#xff1a…

如何设置postgresql数据库的账户密码

说明&#xff1a;在我的云服务器上&#xff0c;postgres是使用yum的方式安装的&#xff0c;不需要设置postgres账户的密码&#xff0c;本文介绍安装后如何手动设置postgres账户的密码&#xff1b; postgres数据库安装&#xff0c;参考下面这篇文章&#xff1a; PostgreSQL安装…

SMS-Activate 接码

pip install smsactivate from smsactivate.api import SMSActivateAPI 1. 获取密匙 在https://sms-activate.io/cn/api2#balans页面点击生成密匙 2. 查看所需服务的代码符号&#xff0c;点击见表 查看国家代码符号点击见表 3. 获取手机号 def get_phone_new(self):api SMS…

Intel任命Micron技术开发主管领导Intel Foundry制造运营

- **新闻要点**&#xff1a;Intel聘请了Micron的技术开发主管Dr. Naga Chandrasekaran担任首席全球运营官、执行副总裁以及Intel Foundry制造和供应链组织的总经理。他将负责Intel的所有制造运营事务。 #### 任命背景 - **领导团队**&#xff1a;Chandrasekaran将成为Intel执行…

MySQL 查询 limit 100000000, 10 和 limit 10 速度一样快吗?

MySQL 查询 limit 100000000, 10 和 limit 10 速度一样快吗&#xff1f; MySQL内部分为server层和存储引擎层。一般情况下存储引擎都用innodb。 server层有很多模块&#xff0c;其中需要关注的是执行器是用于跟存储引擎打交道的组件。 执行器可以通过调用存储引擎提供的接口&…

Transformer-Bert---散装知识点---mlm,nsp,较之经典tran的区别和实际应用方式

本文记录的是笔者在了解了transformer结构后嗑bert中记录的一些散装知识点&#xff0c;有时间就会整理收录&#xff0c;希望最后能把transformer一个系列都完整的更新进去。 1.自监督学习 bert与原始的transformer不同&#xff0c;bert是使用大量无标签的数据进行预训练&#…

LINUX 孤儿进程和僵尸进程

1、孤儿进 一个父进程退出&#xff0c;而它的一个或多个子进程还在运行&#xff0c;那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养&#xff0c;并由init进程对它们完成状态收集工作 为了释放子进程的占用的系统资源&#xff1a; 进程结束之后&#xf…

意象万千的紫

文章目录 引言中国紫梦幻紫莫奈紫引言 2024巴黎奥运会的临近,很多网友都被“法式浪漫奥运紫”惊艳了,大到赛场跑道,小到一个羽毛球的设计,紫色的嵌入使竞技体育增添了不少梦幻的感觉。 中国紫 清代: 陈曾寿 【 雪青衫子绮罗新,一晌当前色相真】 青莲 五代十国李璟 “青…

mysql数据库管理(2)

数据库增删改查 将sql文件传到Linux /home目录下面 mysql –uroot –p create database test; use test; source myemployees.sql&#xff08;如果在home目录下&#xff0c;直接source .sql&#xff09; show tables; select * from departments; ps&#xff1a;SQL 语言大小写…