Elasticsearch-06-Elasticsearch Java API Client

前言

简介

在 Elasticsearch7.15版本之后,Elasticsearch官方将它的高级客户端 RestHighLevelClient标记为弃用状态。同时推出了全新的 Java API客户端 Elasticsearch Java API Client,该客户端也将在 Elasticsearch8.0及以后版本中成为官方推荐使用的客户端。

Elasticsearch Java API Client 支持除 Vector tile search API 和 Find structure API 之外的所有 Elasticsearch API。且支持所有API数据类型,并且不再有原始JsonValue属性。它是针对Elasticsearch8.0及之后版本的客户端,所以我们需要学习新的Elasticsearch Java API Client的使用方法。

为什么要抛弃High Level Rest:

  • 客户端"too heavy",相关依赖超过 30 MB,且很多都是非必要相关的;api 暴露了很多服务器内部接口

  • 一致性差,仍需要大量的维护工作。

  • 客户端没有集成 json/object 类型映射,仍需要自己借助字节缓存区实现。

Java API Client最明显的特征:

  • 支持lambda表达式操作ES
  • 支持Builder建造者模式操作ES,链式代码具有较强可读性.
  • 应用程序类能够自动映射为Mapping.
  • 所有Elasticsearch API的强类型请求和响应。
  • 所有API的阻塞和异步版本
  • 将协议处理委托给http客户端(如Java低级REST客户端),该客户端负责处理所有传输级问题:HTTP连接池、重试、节点发现等。

官方地址

https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/indexing.html

简单使用

1:导包

这里记住你的elasticsearch-java必须对应你电脑上装的ES版本

	<dependency><groupId>co.elastic.clients</groupId><artifactId>elasticsearch-java</artifactId><version>7.17.6</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.12.3</version></dependency><dependency><groupId>jakarta.json</groupId><artifactId>jakarta.json-api</artifactId><version>2.0.1</version></dependency>

2:开启链接

        //创建一个低级的客户端final RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();//创建JSON对象映射器final RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());//创建API客户端final ElasticsearchClient client = new ElasticsearchClient(transport);

3:关闭链接

        client.shutdown();transport.close();restClient.close();

4:完整代码

public class Client {public static void main(String[] args) throws IOException {//创建一个低级的客户端final RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();//创建JSON对象映射器final RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());//创建API客户端final ElasticsearchClient client = new ElasticsearchClient(transport);//查询所有索引-------------------------------------------------------------------------------------final GetIndexResponse response = client.indices().get(query -> query.index("_all"));final IndexState products = response.result().get("products");System.out.println(products.toString());//关闭client.shutdown();transport.close();restClient.close();}
}

JsonData类

原始JSON值。可以使用JsonpMapper将其转换为JSON节点树或任意对象。 此类型在API类型中用于没有静态定义类型或无法表示为封闭数据结构的泛型参数的值。 API客户端返回的此类实例保留对客户端的JsonpMapper的引用,并且可以使用to(class)转换为任意类型,而不需要显式映射器

我们一般在ES的DSL范围查询中会使用到!
核心方法:

  • to:将此对象转换为目标类。必须在创建时提供映射器
  • from:从读取器创建原始JSON值
  • of:从现有对象创建原始JSON值,以及用于进一步转换的映射器
  • deserialize:使用反序列化程序转换此对象。必须在创建时提供映射器

高阶使用

1:ES配置类

// 配置的前缀
@ConfigurationProperties(prefix = "elasticsearch") 
@Configuration
public class ESClientConfig {/*** 多个IP逗号隔开*/@Setterprivate String hosts;/*** 同步方式* * @return*/@Beanpublic ElasticsearchClient elasticsearchClient() {HttpHost[] httpHosts = toHttpHost();// Create the RestClient //RestClient restClient = RestClient.builder(httpHosts).build();RestClient restClient = RestClient.builder(httpHosts).setHttpClientConfigCallback(httpClientBuilder->httpClientBuilder.setDefaultHeaders(listOf(new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()))).addInterceptorLast((HttpResponseInterceptor) (response, context)-> response.addHeader("X-Elastic-Product", "Elasticsearch"))).build();// Create the transport with a Jackson mapperRestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());// create the API clientreturn new ElasticsearchClient(transport);}/*** 异步方式* * @return*/@Beanpublic ElasticsearchAsyncClient elasticsearchAsyncClient() {HttpHost[] httpHosts = toHttpHost();RestClient restClient = RestClient.builder(httpHosts).build();RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());return new ElasticsearchAsyncClient(transport);}/*** 解析配置的字符串hosts,转为HttpHost对象数组** @return*/private HttpHost[] toHttpHost() {if (!StringUtils.hasLength(hosts)) {throw new RuntimeException("invalid elasticsearch configuration. elasticsearch.hosts不能为空!");}// 多个IP逗号隔开String[] hostArray = hosts.split(",");HttpHost[] httpHosts = new HttpHost[hostArray.length];HttpHost httpHost;for (int i = 0; i < hostArray.length; i++) {String[] strings = hostArray[i].split(":");httpHost = new HttpHost(strings[0], Integer.parseInt(strings[1]), "http");httpHosts[i] = httpHost;}return httpHosts;}}

2:查询所有索引

//省略连接...final GetIndexResponse all = client.indices().get(query -> query.index("_all"));System.out.println(all.toString());
//省略关闭...

3:查询某个索引

        //查询某个索引final GetIndexResponse products = client.indices().get(query -> query.index("products"));System.err.println(products.toString());

4:创建索引

		//查询某个索引是否存在boolean exists = client.indices().exists(query -> query.index("products")).value();System.out.println(exists);if (exists) {System.err.println("索引已存在");} else {final CreateIndexResponse products = client.indices().create(builder -> builder.index("products"));System.err.println(products.acknowledged());}

5:删除指定索引

        //删除指定索引boolean exists = client.indices().exists(query -> query.index("products")).value();System.out.println(exists);if (exists) {DeleteIndexResponse response = client.indices().delete(query -> query.index("products"));System.err.println(response.acknowledged());} else {System.err.println("索引不存在");}

6:查询索引的映射

        //查询映射信息final GetIndexResponse response = client.indices().get(builder -> builder.index("produces"));System.err.println(response.result().get("produces").mappings());

7:创建索引指定映射

numberOfReplicas(“1”):设置副本
numberOfShards(“1”):设置分片

        //创建索引指定映射,分片和副本信息final CreateIndexResponse response = client.indices().create(builder ->builder.settings(indexSetting -> indexSetting.numberOfReplicas("1").numberOfShards("1")).mappings(map -> map.properties("name", propertyBuilder -> propertyBuilder.keyword(keywordProperty -> keywordProperty)).properties("price", propertyBuilder -> propertyBuilder.double_(doubleNumProperty -> doubleNumProperty)).properties("des", propertyBuilder -> propertyBuilder.text(textProperty -> textProperty.analyzer("ik_smart").searchAnalyzer("ik_smart")))).index("produces"));

8:创建文档

使用HashMap作为数据存储容器

        //创建文档//1.创建HashMap进行存储数据,文档要对应映射final HashMap<String, Object> doc = new HashMap<>();doc.put("name","辣条");doc.put("age",12);doc.put("id","11111");//2.将文档存入索引中final IndexResponse response = client.index(builder -> builder.index("produces").id(doc.get("id")).document(doc));System.err.println(response.version());

使用自定义类作为数据存储容器

实体类

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Produce {private String id;private String name;private double age;
}
        //创建文档final Produce produce = new Produce("123", "小明", 18);final IndexResponse response = client.index(builder -> builder.index("produces").id(produce.getId()).document(produce));System.err.println(response.version());

使用外部JSON数据创建

这里要注意我们需要使用StringReader进行读取时使用replace函数将设置的’改为",当然这在真实的业务中肯定不会有,因为真实业务中一定是标准的JSON数据,无需使用replace进行替换了

        //创建文档final StringReader input = new StringReader("{'name':'农夫三拳','price':3.00,'des':'农夫三拳有点甜'}".replace('\'', '"'));final IndexResponse response = client.index(builder -> builder.index("produces").id("44514").withJson(input));System.err.println(response.version());

9: 查询所有文档

 final SearchResponse<Object> response = client.search(builder -> builder.index("produces"), Object.class);final List<Hit<Object>> hits = response.hits().hits();hits.forEach(x-> System.err.println(x));

10:根据ID查询文档

使用HashMap对应查询

        //查询文档final GetResponse<Map> response = client.get(builder -> builder.index("produces").id("116677"), Map.class);final Map source = response.source();source.forEach((x,y)->{System.err.println(x+":"+y);});

使用自定义类对应查询

        final GetResponse<Produce> response1 = client.get(builder -> builder.index("produces").id("aabbcc123"), Produce.class);final Produce source1 = response1.source();System.err.println(source1.toString());

11:删除文档

        final GetResponse<Produce> response1 = client.get(builder -> builder.index("produces").id("aabbcc123"), Produce.class);final Produce source1 = response1.source();System.err.println(source1.toString());

12:修改文档

全覆盖

        //修改文档(覆盖)final Produce produce = new Produce("ccaabb123", "旺仔摇滚洞", "旺仔摇滚洞乱摇乱滚", 10.23D);final UpdateResponse<Produce> response = client.update(builder -> builder.index("produces").id("aabbcc123").doc(produce), Produce.class);System.err.println(response.shards().successful());

修改部分文档

区别在于我们需要设置.docAsUpsert(true)表明是修改部分而不是覆盖

        //修改文档(部分修改)
//        final Produce produce = new Produce("ccaabb123", "旺仔摇滚洞", "旺仔摇滚洞乱摇乱滚", 10.23D);final Produce produce = new Produce();produce.setName("旺仔摇不动");final UpdateResponse<Produce> response = client.update(builder -> builder.index("produces").id("aabbcc123").doc(produce).docAsUpsert(true), Produce.class);System.err.println(response.shards().successful());

13:批量操作

批量新增

		produceList.add(produce1);produceList.add(produce2);produceList.add(produce3);//构建BulkRequestfinal BulkRequest.Builder br = new BulkRequest.Builder();for (Produce produce : produceList) {br.operations(op->op.index(idx->idx.index("produces").id(produce.getSku()).document(produce)));}final BulkResponse response = client.bulk(br.build());

批量删除

List<BulkOperation> bulkOperations = new ArrayList<>();// 向集合中添加需要删除的文档id信息for (int i = 0; i < dto.getIds().size(); i++) {int finalI = i;bulkOperations.add(BulkOperation.of(b -> b.delete((d -> d.index(dto.getIndex()).id(dto.getIds().get(finalI))))));}// 调用客户端的bulk方法,并获取批量操作响应结果BulkResponse response = client.bulk(e -> e.index(dto.getIndex()).operations(bulkOperations));

DSL查询

1:matchAll查询所有文档

        //matchAllfinal SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.matchAll(v->v)), Produce.class);System.err.println(response.hits().hits());

2:match 根据字段查询

        //简单query方式查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.match(t ->t.field("name").query("龙虎万精油"))), Produce.class);System.err.println(response.hits().hits());

3:多id查询

        //多ID查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.ids(sid->sid.values("1000","1001"))), Produce.class);System.err.println(response.hits().hits());

4:term 不分词查询

        //term不分词条件查询final SearchResponse<Produce> response = client.search(builder -> builder.index("produces").query(q -> q.term(t -> t.field("name").value("风油精"))), Produce.class);System.err.println(response.hits().hits());

5:范围查询

        //范围查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.range(r ->r.field("price").gt(JsonData.of(5D)).lt(JsonData.of(15D)))),Produce.class);System.err.println(response.hits().hits());

6: 前缀查询

  final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.prefix(p->p.field("name").value("六"))),Produce.class);System.err.println(response.hits().hits());

7:匹配查询

//匹配查询

  final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.wildcard(w->w.field("name").value("风*"))),Produce.class);System.err.println(response.hits().hits());

?单字符匹配

        //匹配查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.wildcard(w->w.field("name").value("风?精"))),Produce.class);System.err.println(response.hits().hits());

8:模糊查询

        //模糊查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.fuzzy(f->f.field("name").value("六仙花露水"))),Produce.class);System.err.println(response.hits().hits());

9:多条件查询

使用bool关键字配合must,should,must_not

  • must:所有条件必须同时成立
  • must_not:所有条件必须同时不成立
  • should:所有条件中成立一个即可
        //多条件final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q ->q.bool(b ->b.must(t ->t.term(v ->v.field("name").value("旺仔摇不动"))).must(t2 ->t2.term(v2 ->v2.field("price").value(0.0D))))),Produce.class);System.err.println(response.hits().hits());

或者创建BoolQuery.Builder,以便进行业务判断是否增加查询条件

 List<FieldValue> fieldValues = new ArrayList<>();fieldValues.add(FieldValue.of(10));fieldValues.add(FieldValue.of(100));BoolQuery.Builder boolQuery = new BoolQuery.Builder();boolQuery.must(t->t.terms(v->v.field("label").terms(term->term.value(fieldValues))));boolQuery.must(t->t.match(f->f.field("name").query("旺仔")));SearchResponse<Object> search = elasticsearchClient.search(builder -> builder.index("my_test_index").query(q->q.bool(boolQuery.build())),Object.class);

10:多字段查询-multiMatch

        //多字段查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q->q.multiMatch(qs->qs.query("蚊虫叮咬 辣眼睛").fields("name","des"))),Produce.class);System.err.println(response.hits().hits());

11:高亮显示

我们注意要设置前缀和后缀

        //高亮显示final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q -> q.match(v -> v.field("name").query("风油精"))).highlight(h -> h.preTags("<span>").postTags("<span>").fields("name", hf -> hf)),Produce.class);System.err.println(response.toString());

12:分页查询

我们使用match_all进行全部搜索的时候使用size关键字设置每一页的大小,使用from关键字设置页码
from的计算公式:(页码-1)*size

        //分页查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q->q.matchAll(v->v)).size(2).from(0),Produce.class);System.err.println(response.hits().hits());

13:排序

使用sort关键字指定需要进行排序的字段设置排序类型即可,我们这里会使用到SortOrder枚举类来进行指定排序方式

desc:降序
asc:升序

        //排序final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q->q.matchAll(v->v)).sort(builder1 -> builder1.field(f->f.field("price").order(SortOrder.Asc))),Produce.class);System.err.println(response.hits().hits());

14:指定字段查询

使用_source关键字在数组中设置需要展示的字段
值得注意的是在source方法中需要我们写filter去指定是include包含或是exclude去除xx字段

        //指定字段查询final SearchResponse<Produce> response = client.search(builder ->builder.index("produces").query(q->q.matchAll(v->v)).source(s->s.filter(v->v.includes("price","des"))),Produce.class);System.err.println(response.hits().hits());

15:聚合查询-求最大值

SearchResponse<Object> search = elasticsearchClient.search(builder ->builder.index("my_test_index").from(0).size(1).aggregations("aa", t ->t.max(f->f.field("type"))), Object.class);EsResult esResult = EsUtils.searchAnalysis(search);Aggregate aa = esResult.getAggregations().get("aa");LongTermsAggregate lterms = aa.lterms();Buckets<LongTermsBucket> buckets = lterms.buckets();List<LongTermsBucket> array = buckets.array();

16:桶聚合查询-劣势 group by

SearchResponse<JSONObject> search = elasticsearchClient.search(builder ->builder.index(EsIndexConstants.article_info).query(t->t.range(f->f.field("create_time").gte(JsonData.of(startDate)).lte(JsonData.of(endDate)))).from(0).size(1).aggregations("countValue", t ->t.terms(f -> f.field("ata_type.keyword"))), JSONObject.class);
Aggregate countValue = search .getAggregations().get("countValue");
List<StringTermsBucket> array = countValue.sterms().buckets().array();

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

canvas基础3 -- 交互

点击交互 使用 isPointInPath(x, y) 判断鼠标点击位置在不在图形内 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"&…

scrapy框架爬取数据(创建一个scrapy项目+xpath解析数据+通过pipelines管道实现数据保存+中间件)

目录 一、创建一个scrapy项目 二、xpath解析数据 三、通过pipelines管道实现数据保存 四、中间件 一、创建一个scrapy项目 1.创建一个文件夹&#xff1a;C06 在终端输入以下命令&#xff1a; 2.安装scrapy:pip install scrapy 3.来到文件夹下&#xff1a;cd C06 4.创建…

拿到 phpMyAdmin 如何获取权限

文章目录 拿到 phpMyAdmin 如何获取权限1. outfile 写一句话木马2. general_log_file 写一句话木马 拿到 phpMyAdmin 如何获取权限 1. outfile 写一句话木马 尝试使用SQL注入写文件的方式&#xff0c;执行 outfile 语句写入一句话木马。 select "<?php eval($_REQU…

电商独立站前端、后端、接口协议和电商API接口请求方式

前端是做什么的&#xff1f;后端是做什么的&#xff1f;哪些事情&#xff0c;是前端做的&#xff1f;哪些事情&#xff0c;是后端做的&#xff1f;前后端一体是什么意思&#xff1f;接口、接口协议、接口请求方式…… 1、前端所写的程序&#xff0c;主要运行在客户端&#xff…

KaTex语法学习

文章目录 KaTex语法学习Examples行内的公式 Inline多行公式 Multi line KaTeX vs MathJax KaTex语法学习 katex参考资料 吴文中-数学公式编辑器 Examples 行内的公式 Inline E m c 2 Emc^2 Emc2 Inline 行内的公式 E m c 2 Emc^2 Emc2 行内的公式&#xff0c;行内的 E …

postgresql14管理(六)-备份与恢复

定义 备份&#xff08;backup&#xff09;&#xff1a;通过物理复制或逻辑导出的方式&#xff0c;将数据库的文件或结构和数据拷贝到其他位置进行存储&#xff1b; 还原&#xff08;restore&#xff09;&#xff1a;是一种不完全的恢复。使用备份文件将数据库恢复到备份时的状…

项目|金额场景计算BigDecimal使用简记

前言 在实际项目开发中&#xff0c;我们经常会遇到一些金额计算&#xff0c;分摊等问题&#xff0c;通常我们都使用java.math.BigDecimal 来完成各种计算&#xff0c;避免使用浮点数float,double来计算金额&#xff0c;以免丢失精度&#xff0c;以下是博主部分使用场景和使用Bi…

[Docker]三.Docker 部署nginx,以及映射端口,挂载数据卷

一.Docker 部署 Nginx 以及端口映射 Docker 部署 Nginx,首先需要下载nginx镜像,然后启动这个镜像,就运行了一个nginx的容器了 1.下载 nginx 镜像并启动容器 #查看是否存在nginx镜像:发现没有nginx镜像 [rootlocalhost zph]# docker images | grep nginx#下载nginx镜像 [rootl…

安装 GMP、NTL、CTMalloc ,编译 OpenFHE

参考文献&#xff1a; [ABB22] Al Badawi A, Bates J, Bergamaschi F, et al. Openfhe: Open-source fully homomorphic encryption library[C]//Proceedings of the 10th Workshop on Encrypted Computing & Applied Homomorphic Cryptography. 2022: 53-63.openfheorg/o…

【Spring】IOC容器与Bean的常用属性配置

文章目录 1.前言2.IOC容器2.1 BeanFactory 容器2.2 ApplicationContext 容器 3.Bean的常用属性配置4. 总结 1.前言 在之前的文章-IOC的快速入门中讲过Bean这个概念. 本来就来介绍容器与Bean的常用属性配置 在Spring框架中&#xff0c;Bean指的是被Spring加载生成出来的对象。 …

12、SpringCloud -- redis库存和redis预库存保持一致、优化后的压测效果

目录 redis库存和redis预库存保持一致问题的产生需求:代码:测试:优化后的压测效果之前的测试数据优化后的测试数据redis库存和redis预库存保持一致 redis库存是指初始化是从数据库中获取最新的秒杀商品列表数据存到redis中 redis的预库存是指每个秒杀商品每次成功秒杀之后…

永恒之蓝漏洞 ms17_010 详解

文章目录 永恒之蓝 ms 17_0101.漏洞介绍1.1 影响版本1.2 漏洞原理 2.信息收集2.1 主机扫描2.2 端口扫描 3. 漏洞探测4. 漏洞利用5.后渗透阶段5.1创建新的管理员账户5.2开启远程桌面5.3蓝屏攻击 永恒之蓝 ms 17_010 1.漏洞介绍 永恒之蓝&#xff08;ms17-010&#xff09;爆发于…

安装虚拟机(VMware)保姆级教程及配置虚拟网络编辑器和安装WindowsServer以及宿主机访问虚拟机和配置服务器环境

目录 一、操作系统 1.1.什么是操作系统 1.2.常见操作系统 1.3.个人版本和服务器版本的区别 1.4.Linux的各个版本 二、VMware Wworkstation Pro虚拟机的安装 1.下载与安装 注意&#xff1a;VMWare虚拟网卡 2.配置虚拟网络编辑器 三、安装配置 WindowsServer 1.创建虚拟…

自动化项目实战 [个人博客系统]

自动化博客项目 用户注册登录验证效验个人博客列表页博客数量不为 0 博客系统主页写博客 我的博客列表页效验 刚发布的博客的标题和时间查看 文章详情页删除文章效验第一篇博客 不是 "自动化测试" 注销退出到登录页面,用户名密码为空 用户注册 Order(1)Parameterized…

QT5.15在Ubuntu22.04上编译流程

在我们日常遇到的很多第三方软件中&#xff0c;有部分软件针对开发人员&#xff0c;并不提供预编译成果物&#xff0c;而是需要开发人员自行编译&#xff0c;此类问题有时候不是问题&#xff08;编译步骤的doc详细且清晰时&#xff09;&#xff0c;但有时候又很棘手&#xff08…

数据结构上机实验——二叉树的实现、二叉树遍历、求二叉树的深度/节点数目/叶节点数目、计算二叉树度为1或2的节点数、判断二叉树是否相似

文章目录 数据结构上机实验1.要求2.二叉树的实现2.1创建一颗二叉树2.2对这棵二叉树进行遍历2.3求二叉树的深度/节点数目/叶节点数目2.4计算二叉树中度为 1 或 2 的结点数2.5判断2棵二叉树是否相似&#xff0c;若相似返回1&#xff0c;否则返回0 3.全部源码测试&#xff1a;Bina…

问题 S: 一只小蜜蜂...(初始化dp)

1.注意点&#xff1a; 该题递推公式为斐波那契数列&#xff0c;而n达到50&#xff0c;是非常大的数 &#xff0c; 故应用循环代替递归&#xff0c;同时记录数据 同时用long long数组储存 ​​ 2.注意点&#xff1a;初始化起点&#xff0c;切忌重新递归找数 可以直接初始化所…

前端重新部署如何通知用户更新

标题解决方案 常用的webSocket解决方案 webSocket; 大致逻辑思考应该是前端在部署好后向服务器发送一个状态变更通知&#xff1b;服务器接收后主动向前端push&#xff1b;前端通过心跳检测&#xff0c;接收到相关更新时弹出提示&#xff0c;让用户确认更新&#xff1b; 缺点&a…

什么是Props?

Props是Vue框架中的一个特性&#xff0c;用于父组件向子组件传递数据。它允许父组件将数据传递给子组件&#xff0c;并在子组件中进行使用和显示。 Props的作用是实现父子组件之间的数据通信。通过Props&#xff0c;父组件可以向子组件传递数据&#xff0c;使得子组件能够接收…

设计一个高效算法,将顺序表L的所有元素逆置,要求算法的空间复杂度为O(1)

初始化及打印函数 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #define MaxSize 10//定义最大长度 int InitArr[10] { 1,2,3,4,5,6,7,8,9,10 };typedef struct {int data[MaxSize];//用静态的数据存放数据元素int length;//顺序表当前长度 }Sqlist;//顺序表的类…