SpringBoot3整合Elasticsearch8.x之全面保姆级教程
整合ES
环境准备
- 安装配置
ES
:https://blog.csdn.net/qq_50864152/article/details/136724528
- 安装配置
Kibana
:https://blog.csdn.net/qq_50864152/article/details/136727707
- 新建项目:新建名为
web
的SpringBoot3
项目
elasticsearch-java
公共配置
- 介绍:一个开源的高扩展的分布式全文检索引擎,可以近乎实时的存储 和检索数据
- 依赖:
web
模块引入elasticsearch-java
依赖---
但其版本必须与你下载的ES
的版本一致
<!-- 若不存在Spring Data ES的某个版本支持你下的ES版本,则使用 -->
<!-- ES 官方提供的在JAVA环境使用的依赖 -->
<dependency><groupId>co.elastic.clients</groupId><artifactId>elasticsearch-java</artifactId><version>8.11.1</version>
</dependency><!-- 和第一个依赖是一起的,为了解决springboot项目的兼容性问题 -->
<dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId>
</dependency>
- 配置:
web
模块dev
目录application-dal
添加
使用
open+@Value("${elasticsearch.open}")
的方式不能放到Nacos
配置中心
# elasticsearch配置
elasticsearch:# 自定义属性---设置是否开启ES,false表不开窍ESopen: true# es集群名称,如果下载es设置了集群名称,则使用配置的集群名称clusterName: eshosts: 127.0.0.1:9200# es 请求方式scheme: http# es 连接超时时间connectTimeOut: 1000# es socket 连接超时时间socketTimeOut: 30000# es 请求超时时间connectionRequestTimeOut: 500# es 最大连接数maxConnectNum: 100# es 每个路由的最大连接数maxConnectNumPerRoute: 100
- 配置:
web
模块config
包下新建ElasticSearchConfig
类
package cn.bytewisehub.pai.web.config;import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Slf4j
@Data
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
public class ElasticSearchConfig {// 是否开启ESprivate Boolean open;// es 集群host ip 地址private String hosts;// es用户名private String userName;// es密码private String password;// es 请求方式private String scheme;// es集群名称private String clusterName;// es 连接超时时间private int connectTimeOut;// es socket 连接超时时间private int socketTimeOut;// es 请求超时时间private int connectionRequestTimeOut;// es 最大连接数private int maxConnectNum;// es 每个路由的最大连接数private int maxConnectNumPerRoute;// es api keyprivate String apiKey;public RestClientBuilder creatBaseConfBuilder(String scheme){// 1. 单节点ES Host获取String host = hosts.split(":")[0];String port = hosts.split(":")[1];// The value of the schemes attribute used by noSafeRestClient() is http// but The value of the schemes attribute used by safeRestClient() is httpsHttpHost httpHost = new HttpHost(host, Integer.parseInt(port),scheme);// 2. 创建构建器对象//RestClientBuilder: ES客户端库的构建器接口,用于构建RestClient实例;允许你配置与Elasticsearch集群的连接,设置请求超时,设置身份验证,配置代理等RestClientBuilder builder = RestClient.builder(httpHost);// 连接延时配置builder.setRequestConfigCallback(requestConfigBuilder -> {requestConfigBuilder.setConnectTimeout(connectTimeOut);requestConfigBuilder.setSocketTimeout(socketTimeOut);requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);return requestConfigBuilder;});// 3. HttpClient 连接数配置builder.setHttpClientConfigCallback(httpClientBuilder -> {httpClientBuilder.setMaxConnTotal(maxConnectNum);httpClientBuilder.setMaxConnPerRoute(maxConnectNumPerRoute);return httpClientBuilder;});return builder;}
}
- 测试:
web
模块test
目录下新建ElasticSearchTest
类
@Slf4j
@SpringBootTest
public class ElasticSearchTest {@Value("${elasticsearch.open}")// 是否开启ES,默认开启String open = "true";
}
直接连接ES
- 设置:
ES
Elasticsearch.yml
的xpack.security.enabled
属性设置为false
xpack.security.enabled
:
● 默认true
:必须使用账号连接ES
● 若为false
:必须使用http://localhost:9200/
访问ES
服务+
启动Kibana
服务会失败+
不需要使用账号连接,但必须使用HTTP
连接
- 添加:
ElasticSearchConfig
类添加下列方法
/**
* @function: 创建使用http连接来直接连接ES服务器的客户端
* 如果@Bean没有指定bean的名称,那么这个bean的名称就是方法名
*/
@Bean(name = "directConnectionESClient")
public ElasticsearchClient directConnectionESClient(){RestClientBuilder builder = creatBaseConfBuilder((scheme == "http")?"http":"http");//Create the transport with a Jackson mapperElasticsearchTransport transport = new RestClientTransport(builder.build(), new JacksonJsonpMapper());//And create the API clientElasticsearchClient esClient = new ElasticsearchClient(transport);return esClient;
};
- 添加:
ElasticSearchTest
类中添加下列代码---
索引名必须小写 - 运行:设置跳过测试
--->
手动运行/不跳过--->
直接install
,但不运行测试
@Resource(name = "directConnectionESClient")
ElasticsearchClient directConnectionESClient;@Test
public void directConnectionTest() throws IOException {if (open.equals("true")) {//创建索引CreateIndexResponse response = directConnectionESClient.indices().create(c -> c.index("direct_connection_index"));log.info(response.toString());
}
else{log.info("es is closed");
}
}
账号密码连接ES
- 设置:
ES
Elasticsearch.yml
的xpack.security.enabled
属性使用默认值+
xpack.security.http.ssl.enabled
设置为false
注意:若
xpack.security.enabled
属性为false
,则xpack.security.http.ssl.enabled
属性不生效,即相当于设置为false
;所有以xpack
开头的属性都不会生效
ES
Elasticsearch.yml
的xpack.security.http.ssl.enabled
:
● 默认true
:必须使用https://localhost:9200/
访问ES
服务+
启动Kibana
服务会成功+
需要使用账号连接+
必须使用HTTPS
连接
● 若为false
:必须使用http://localhost:9200/
访问ES
服务+
启动Kibana
服务会失败+需要使用账号连接,但必须使用HTTP连接
- 配置:
dev
目录application-dal
中添加下列配置
# elasticsearch配置
elasticsearch:userName: #自己的账号名password: #自己的密码
- 添加:
ElasticSearchTest
类中添加下列代码---
索引名必须小写+
不能有空格 - 运行:设置跳过测试
--->
手动运行/不跳过--->
直接install
,但不运行测试
@Resource(name = "accountConnectionESClient")
ElasticsearchClient accountConnectionESClient;@Test
public void accountConnectionTest() throws IOException {if (open.equals("true")) {//创建索引CreateIndexResponse response = accountConnectionESClient.indices().create(c -> c.index("account_connection_index"));log.info(response.toString());
}
else{log.info("es is closed");
}
}
证书账号连接ES
- 设置:
ES
Elasticsearch.yml
的xpack.security.enabled
和xpack.security.http.ssl.enabled
配置项使用默认值
设置为
true
后,ES
就走https
,若scheme
为http
,则报Unrecognized
SSLmessage
错误
- 配置:将
dev
目录application-dal
中elasticsearch.scheme
配置项改成https
- 证书添加:终端输入
keytool -importcert -alias es_https_ca -keystore "D:\computelTool\Java\JDK\JDK21\lib\security\cacerts" -file "D:\computelTool\database\elasticsearch8111\config\certs\http_ca.crt"
keytool -delete -alias es_https_ca -keystore "D:\computelTool\Java\JDK\JDK21\lib\security\cacerts"
---
与上面的命令相反
- 拷贝:将
ESconfig
目录下certs
目录下的http_ca.crt
文件拷贝到web
模块resource
目录 - 添加:
ElasticSearchConfig
类添加下列方法
/**
* @function: 创建用于安全连接(证书 + 账号)ES服务器的客户端
* 如果@Bean没有指定bean的名称,那么这个bean的名称就是方法名
*/
@Bean(name = "accountAndCertificateConnectionESClient")
public ElasticsearchClient accountAndCertificateConnectionESClient() {RestClientBuilder builder = creatBaseConfBuilder( (scheme == "https")?"https":"https");// 1.账号密码的配置//CredentialsProvider: 用于提供 HTTP 身份验证凭据的接口; 允许你配置用户名和密码,以便在与服务器建立连接时进行身份验证CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));// 2.设置自签证书,并且还包含了账号密码builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder.setSSLContext(buildSSLContext()).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).setDefaultCredentialsProvider(credentialsProvider));RestClientTransport transport = new RestClientTransport(builder.build(), new JacksonJsonpMapper());//And create the API clientElasticsearchClient esClient = new ElasticsearchClient(transport);return esClient;
}private static SSLContext buildSSLContext() {// 读取http_ca.crt证书ClassPathResource resource = new ClassPathResource("http_ca.crt");SSLContext sslContext = null;try {// 证书工厂CertificateFactory factory = CertificateFactory.getInstance("X.509");Certificate trustedCa;try (InputStream is = resource.getInputStream()) {trustedCa = factory.generateCertificate(is);}// 密钥库KeyStore trustStore = KeyStore.getInstance("pkcs12");trustStore.load(null, "liuxiansheng".toCharArray());trustStore.setCertificateEntry("ca", trustedCa);SSLContextBuilder sslContextBuilder = SSLContexts.custom().loadTrustMaterial(trustStore, null);sslContext = sslContextBuilder.build();} catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException |KeyManagementException e) {log.error("ES连接认证失败", e);}return sslContext;
}
- 测试:
ElasticSearchTest
类添加
@Resource(name = "accountAndCertificateConnectionESClient")
ElasticsearchClient accountAndCertificateConnectionESClient;@Test
public void accountAndCertificateConnectionTest() throws IOException {if (open.equals("true")) {//创建索引CreateIndexResponse response = accountAndCertificateConnectionESClient.indices().create(c -> c.index("account_and_certificate_connection_index"));log.info(response.toString());System.out.println(response.toString());
}
else{log.info("es is closed");
}
}
Spring Data ES
公共配置
- 依赖:
web
模块引入该依赖---
但其版本必须与你下载的ES
的版本一致
版本:点击
https://spring.io/projects/spring-data-elasticsearch#learn
,点击GA
版本的Reference Doc
,点击version
查看Spring Data ES
与ES
版本的支持关系
参考:
https://www.yuque.com/itwanger/vn4p17/wslq2t/https://blog.csdn.net/qq_40885085/article/details/105023026
<!-- 若存在Spring Data ES的某个版本支持你下的ES版本,则使用 -->
<!-- Spring官方在ES官方提供的JAVA环境使用的依赖的基础上做了封装 -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency><!-- ESTestEntity用到 -->
<dependency><groupId>jakarta.servlet</groupId><artifactId>jakarta.servlet-api</artifactId><version>6.0.0</version><scope>provided</scope>
</dependency><!-- ESTestEntity用到 -->
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope><!--provided:指定该依赖项在编译时是必需的,才会生效, 但在运行时不需要,也不会生效--><!--这样 Lombok 会在编译期静悄悄地将带 Lombok 注解的源码文件正确编译为完整的 class 文件 -->
</dependency>
- 新建:
we
b模块TestEntity
目录新建ESTestEntity
@Data
@EqualsAndHashCode(callSuper = false)
@Document(indexName = "test")
public class ESTestEntity implements Serializable {private static final long serialVersionUID = 1L;@Idprivate Long id;@Field(type = FieldType.Text, analyzer = "ik_max_word")private String content;private String title;private String excerpt;
}
- 新建:
web
模块TestRepository
包下新建ESTestRepository
接口
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;public interface ESTestRepository extends ElasticsearchRepository<ESTestEntity, Long> {
}
直接连接ES
- 配置:
ES
Elasticsearch.yml
的xpack.security.enabled
属性设置为false
xpack.security.enabled
:
● 默认true
:必须使用账号连接ES
● 若为false
:必须使用http://localhost:9200/
访问ES
服务+
启动Kibana
服务会失败+
不需要使用账号连接,但必须使用HTTP
连接
- 配置:
web
模块dev
目录application-dal
添加
spring:elasticsearch:uris:- http://127.0.0.1:9200
- 新建:
web
模块test
目录新建ElasticsearchTemplateTest
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import cn.bytewisehub.pai.web.TestRepository.ESTestRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;@SpringBootTest
public class ElasticsearchTemplateTest {@AutowiredESTestRepository esTestRepository;@AutowiredElasticsearchTemplate elasticsearchTemplate;@Testvoid save() {ESTestEntity esTestEntity = new ESTestEntity();esTestEntity.setId(1L);esTestEntity.setContent("不安全连接");esTestEntity.setTitle("world");esTestEntity.setExcerpt("test");System.out.println(elasticsearchTemplate.save(esTestEntity));}@Testvoid insert() {ESTestEntity esTestEntity = new ESTestEntity();esTestEntity.setId(2L);esTestEntity.setContent("不安全连接");esTestEntity.setTitle("world");esTestEntity.setExcerpt("test");System.out.println(esTestRepository.save(esTestEntity));}
}
- 访问:点击
http://localhost:9200/test/_search
---
查询索引库test
HTTP
连接ES
- 配置:
ES
Elasticsearch.yml
的xpack.security.enabled
属性使用默认值+
xpack.security.http.ssl.enabled
设置为false
ES
Elasticsearch.yml
的xpack.security.http.ssl.enabled
:
● 默认true
:必须使用https://localhost:9200/
访问ES
服务+
启动Kibana
服务会成功+
需要使用账号连接+
必须使用HTTPS
连接
● 若为false
:必须使用http://localhost:9200/
访问ES
服务+
启动Kibana
服务会失败+
需要使用账号连接,但必须使用HTTP
连接
- 配置:
web
模块dev
目录application-dal
添加
spring:elasticsearch:uris:- http://127.0.0.1:9200username: # 账号用户名password: #账号密码
- 修改:
web
模块test
目录下ElasticsearchTemplateTest
修改成这样,其他参见直接连接
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import cn.bytewisehub.pai.web.TestRepository.ESTestRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;@SpringBootTest
public class ElasticsearchTemplateTest {@AutowiredESTestRepository esTestRepository;@AutowiredElasticsearchTemplate elasticsearchTemplate;@Testvoid save() {ESTestEntity esTestEntity = new ESTestEntity();esTestEntity.setId(1L);esTestEntity.setContent("不安全连接");esTestEntity.setTitle("world");esTestEntity.setExcerpt("test");System.out.println(elasticsearchTemplate.save(esTestEntity));}@Testvoid insert() {ESTestEntity esTestEntity = new ESTestEntity();esTestEntity.setId(2L);esTestEntity.setContent("不安全连接");esTestEntity.setTitle("world");esTestEntity.setExcerpt("test");System.out.println(esTestRepository.save(esTestEntity));}
}
- 访问:点击
http://localhost:9200/test/_search
---
查询索引库test
HTTPS
连接ES
- 配置:
ES
Elasticsearch.yml
的xpack.security.enabled
和xpack.security.http.ssl.enabled
属性使用默认值 - 配置:
web
模块dev
目录application-dal
添加
spring:elasticsearch:uris:- https://127.0.0.1:9200username: # 账号用户名password: #账号密码
- 修改:
web
模块test
目录下ElasticsearchTemplateTest
修改成这样,其他参见直接连接
import cn.bytewisehub.pai.web.TestEntity.ESTestEntity;
import cn.bytewisehub.pai.web.TestRepository.ESTestRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;@SpringBootTest
public class ElasticsearchTemplateTest {@AutowiredESTestRepository esTestRepository;@AutowiredElasticsearchTemplate elasticsearchTemplate;@Testvoid save() {ESTestEntity esTestEntity = new ESTestEntity();esTestEntity.setId(1L);esTestEntity.setContent("不安全连接");esTestEntity.setTitle("world");esTestEntity.setExcerpt("test");System.out.println(elasticsearchTemplate.save(esTestEntity));}@Testvoid insert() {ESTestEntity esTestEntity = new ESTestEntity();esTestEntity.setId(2L);esTestEntity.setContent("不安全连接");esTestEntity.setTitle("world");esTestEntity.setExcerpt("test");System.out.println(esTestRepository.save(esTestEntity));}
}
- 访问:点击
http://localhost:9200/test/_search
---
查询索引库test
相关文章:

SpringBoot3整合Elasticsearch8.x之全面保姆级教程
整合ES 环境准备 安装配置ES:https://blog.csdn.net/qq_50864152/article/details/136724528安装配置Kibana:https://blog.csdn.net/qq_50864152/article/details/136727707新建项目:新建名为web的SpringBoot3项目 elasticsearch-java 公…...

微信小程序云开发教程——墨刀原型工具入门(表单组件)
引言 作为一个小白,小北要怎么在短时间内快速学会微信小程序原型设计? “时间紧,任务重”,这意味着学习时必须把握微信小程序原型设计中的重点、难点,而非面面俱到。 要在短时间内理解、掌握一个工具的使用…...

JMeter 批量接口测试
一、背景 最近在进行某中台的接口测试准备,发现接口数量非常多,有6、70个,而且每个接口都有大量的参数并且需要进行各种参数验证来测试接口是否能够正确返回响应值。想了几种方案后,决定尝试使用JMeter的csv读取来实现批量的接口…...

软件游戏缺失unityplayer.dll怎么办,教程5种解决方法
unityplayer.dll是Unity游戏引擎的重要动态链接库文件,它的缺失将直接导致基于该引擎开发的游戏无法正常启动或运行。玩家可能会在尝试打开游戏会提示诸如“找不到unityplayer.dll”或“dll文件丢失”的错误提示,从而无法体验游戏内容。这个问题通常是由…...

Redis相关操作大全一篇全搞定
Redis是单线程吗? Redis 的单线程主要是指 Redis 的网络 10 和键值对读写是由一个线程来完成的,这也是 Redis 对外提供键值存储服务的主要流程。但Redis 的其他功能,比如持久化、异步删除、集群数据同步等,其实是由额外的线程执行的。 Redi…...

排序算法:归并排序(递归)
文章目录 一、归并排序的思路二、代码编写 先赞后看,养成习惯!!!^ _ ^<3 ❤️ ❤️ ❤️ 码字不易,大家的支持就是我坚持下去的动力。点赞后不要忘了关注我哦! 所属专栏:排序算法 一、归并排序的思路 单…...

武汉星起航领航中国跨境电商,助推全球贸易新篇章
在全球经济一体化的浪潮中,跨境电商以其独特的优势成为推动国际贸易增长的重要引擎。作为中国跨境电商行业的领军者,武汉星起航电子商务有限公司以其卓越的能力和经验,正积极推动中国跨境电商走向世界,书写全球贸易的新篇章。 自…...

七、Java中SpringBoot组件集成接入【Minio文件服务器】
七、Java中SpringBoot组件集成接入【Minio文件服务器】 1.Minio介绍2.搭建Minio服务2.1Windows部署2.2Linux部署2.3docker部署 3.Minio可视化操作4.SpringBoot接入Minio1.添加maven依赖2.yaml配置文件3.配置类4.工具类5.控制类 5.常见问题6.其他参考文章 1.Minio介绍 对象存储…...

使用Pygame做一个乒乓球游戏
项目介绍 使用Pygame做一个乒乓球游戏。左侧为电脑,右侧为玩家。 视频地址-YT 视频搬运-B站 视频教程约90分钟。 代码地址 环境:需要pygame库,可用pip安装:pip install pygame 1. 基础版本 首先进行一些初始化,初始…...

力扣---完全平方数
思路: 还是比较好想的,g[i]定义为和为 i 的完全平方数的最少数量。那么递推关系式是g[i]min(g[i-1],g[i-4],g[i-9],...)1,数组初始化是g[0]0,g[1]1。注意这里要对g[0]初始化,(举个例子)因为在遍历到g[4]时&…...

接口测试、postman、测试点提取【主】
接口测试是测试系统组件间接口的一种测试 接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点 测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑依赖关系 文章目录 HTTP接口 & Web Service接口RESTful接口…...

C++ list详解及模拟实现
目录 本节目标 1. list的介绍及使用 1.2 list的使用 2.list的模拟实现 1.对list进行初步的实现 2.头插和任意位置的插入 3.pos节点的删除,头删,尾删 4.销毁list和析构函数 5.const迭代器 6.拷贝构造和赋值操作 3.完整代码 本节目标 1. list的…...

【tls招新web部分题解】
emowebshell (php7.4.21版本漏洞) 非预期 题目提示webshell,就直接尝试一下常见的后门命名的规则 如 shell.php这里运气比较好,可以直接shell.php就出来 要是不想这样尝试的话,也可以直接dirsearch进行目录爆破 然后在phpinfo中直接搜素c…...

力扣热门算法题 52. N 皇后 II,53. 最大子数组和,54. 螺旋矩阵
52. N 皇后 II,53. 最大子数组和,54. 螺旋矩阵,每题做详细思路梳理,配套Python&Java双语代码, 2024.03.20 可通过leetcode所有测试用例。 目录 52. N 皇后 II 解题思路 完整代码 Python Java 53. 最大子数组…...
【OpenVINO】解决OpenVINO在GPU推理中报错的方法
1. 问题描述 使用OpenVINO进行深度学习推理时,通常会借助GPU以提升计算速度。然而,有时候运行程序时候会出现如下错误: <kernel>:8153:2: error: expected identifier or (unroll_for (int i 0; i < TILE_SIZE; i) {^ <kernel…...
AES加密的中文乱码与Java默认编码
0. 背景 win11环境下 java8 idea 开发的项目接口有加密需求,暂时使用AES完成,AES工具类代码如下 public static String aesEncrypt(String content, String key) throws Exception {//指定加密算法Cipher cipher Cipher.getInstance("AES");//创建加密规则&#…...
Node.js笔记 (二)浏览器和服务器
Ajax Ajax是什么 全称:Asynchronous Javascript And Xml. 用javascript执行异步网络请求,可以说是定义了一种编程行为/习惯。 通信双方:浏览器 和 服务器 特点:异步,所以可以在异步请求服务器,在不刷新页…...
面试经典-32-判断子序列
题目 给定字符串 s 和 t ,判断 s 是否为 t 的子序列。 字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列…...
windows使用知识
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言windows使用知识 一、cmd鼠标选中后,程序不运行的解决方案总结 前言 提示:这里可以添加本文要记录的大概内容: windows使用…...
用python如何实现智能合约?如何使用remix编写solidity智能合约并部署上链
目录 用python如何实现智能合约? 直接展示下成功界面 下面分步骤说: remix代码 python链接remix代码...

Spark 之 入门讲解详细版(1)
1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室(Algorithms, Machines, and People Lab)开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目,8个月后成为Apache顶级项目,速度之快足见过人之处&…...

linux arm系统烧录
1、打开瑞芯微程序 2、按住linux arm 的 recover按键 插入电源 3、当瑞芯微检测到有设备 4、松开recover按键 5、选择升级固件 6、点击固件选择本地刷机的linux arm 镜像 7、点击升级 (忘了有没有这步了 估计有) 刷机程序 和 镜像 就不提供了。要刷的时…...

对WWDC 2025 Keynote 内容的预测
借助我们以往对苹果公司发展路径的深入研究经验,以及大语言模型的分析能力,我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际,我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测,聊作存档。等到明…...
Java多线程实现之Callable接口深度解析
Java多线程实现之Callable接口深度解析 一、Callable接口概述1.1 接口定义1.2 与Runnable接口的对比1.3 Future接口与FutureTask类 二、Callable接口的基本使用方法2.1 传统方式实现Callable接口2.2 使用Lambda表达式简化Callable实现2.3 使用FutureTask类执行Callable任务 三、…...
MySQL账号权限管理指南:安全创建账户与精细授权技巧
在MySQL数据库管理中,合理创建用户账号并分配精确权限是保障数据安全的核心环节。直接使用root账号进行所有操作不仅危险且难以审计操作行为。今天我们来全面解析MySQL账号创建与权限分配的专业方法。 一、为何需要创建独立账号? 最小权限原则…...

Python Ovito统计金刚石结构数量
大家好,我是小马老师。 本文介绍python ovito方法统计金刚石结构的方法。 Ovito Identify diamond structure命令可以识别和统计金刚石结构,但是无法直接输出结构的变化情况。 本文使用python调用ovito包的方法,可以持续统计各步的金刚石结构,具体代码如下: from ovito…...

mac 安装homebrew (nvm 及git)
mac 安装nvm 及git 万恶之源 mac 安装这些东西离不开Xcode。及homebrew 一、先说安装git步骤 通用: 方法一:使用 Homebrew 安装 Git(推荐) 步骤如下:打开终端(Terminal.app) 1.安装 Homebrew…...
Python的__call__ 方法
在 Python 中,__call__ 是一个特殊的魔术方法(magic method),它允许一个类的实例像函数一样被调用。当你在一个对象后面加上 () 并执行时(例如 obj()),Python 会自动调用该对象的 __call__ 方法…...

李沐--动手学深度学习--GRU
1.GRU从零开始实现 #9.1.2GRU从零开始实现 import torch from torch import nn from d2l import torch as d2l#首先读取 8.5节中使用的时间机器数据集 batch_size,num_steps 32,35 train_iter,vocab d2l.load_data_time_machine(batch_size,num_steps) #初始化模型参数 def …...

【JavaEE】万字详解HTTP协议
HTTP是什么?-----互联网的“快递小哥” 想象我们正在网上购物:打开淘宝APP,搜索“蓝牙耳机”,点击商品图片,然后下单付款。这一系列操作背后,其实有一个看不见的“快递小哥”在帮我们传递信息,…...