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

ES升级--04--SpringBoot整合Elasticsearch

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • SpringBoot整合Elasticsearch
    • 1.建立项目
    • 2.Maven 依赖
        • [ES 官方网站:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.8/index.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.8/index.html)
    • 3. pom配置
    • 4.证书文件elastic-certificates.p12 拷贝
        • 证书文件elastic-certificates.p12需拷贝到所有ES节点对应的目录下
    • 5.配置类 ElasticsearchConfig
      • SecureRestClientConfig
    • 6.nacos配置参数
    • 7.测试
      • 1.TransportClient
      • 2.ElasticsearchTemplate
      • 3.RestHighLevelClient
      • 4.ElasticsearchRestTemplate


SpringBoot整合Elasticsearch

1.建立项目

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

2.Maven 依赖

进入到 ES 官方网站

ES 官方网站:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.8/index.html

在这里插入图片描述

  • 可以看到有低级和 高级的 Rest Client

在这里插入图片描述

3. pom配置

基于 springboot 2.1.7.RELEASE

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><!-- ES --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId></dependency><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-elasticsearch</artifactId><version>3.2.9.RELEASE</version></dependency><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>6.8.23</version><exclusions><exclusion><groupId>org.elasticsearch.client</groupId><artifactId>transport</artifactId></exclusion><exclusion><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-client</artifactId></exclusion><exclusion><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.elasticsearch.client</groupId><artifactId>transport</artifactId><version>6.8.23</version></dependency><dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-client</artifactId><version>6.8.23</version></dependency><dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>6.8.23</version></dependency><dependency><groupId>org.elasticsearch.plugin</groupId><artifactId>transport-netty4-client</artifactId><version>6.8.23</version></dependency><!-- Elasticsearch客户端依赖版本升级到6.8.32 新增x-pack依赖--><dependency><groupId>org.elasticsearch.client</groupId><artifactId>x-pack-transport</artifactId><version>6.8.23</version></dependency>

4.证书文件elastic-certificates.p12 拷贝

证书文件elastic-certificates.p12需拷贝到所有ES节点对应的目录下
  • 注意:只需创建一次证书并将其复制到所有节点。

在这里插入图片描述

5.配置类 ElasticsearchConfig

支持x-pack 密码验证

/*** ES 配置 -----Elasticsearch 6.8.23* 通过实现配置配,初始化安全Elasticsearch客户端对象,包括ElasticsearchTemplate和RestHighLevelClient两者客户端类* 支持x-pack 密码验证*/@Slf4j
@Configuration
public class SecureElasticsearchConfig {//用户名 elastic@Value("${elasticsearch.xpack.username}")private String xpackUsername = "elastic";//用户密码@Value("${elasticsearch.xpack.password}")private String xpackrPassword;//证书路径  "/home/data/es"@Value("${elasticsearch.xpack.kspath}")private String certPath;//证书密码  ""@Value("${elasticsearch.xpack.kspwd}")private String certPassword;//集群名@Value("${elasticsearch.master.cluster-name}")private String masterClusterName;//节点名@Value("${elasticsearch.master.clusterNodes}")private String clusterNodes;//ip@Value("${elasticsearch.master.address}")private String masterAddress;//端口@Value("${elasticsearch.master.port}")private Integer masterPort;//    // es 连接超时时间
//    private int connectTimeOut;
//    // es socket 连接超时时间
//    private int socketTimeOut;
//    // es 请求超时时间
//    private int connectionRequestTimeOut;
//    // es 最大连接数
//    private int maxConnectNum;
//    // es 每个路由的最大连接数
//    private int maxConnectNumPerRoute;/***集群配置*/private Settings settings() {Settings.Builder builder = Settings.builder();//基础配置builder.put("cluster.name", masterClusterName);builder.put("xpack.security.user", xpackUsername+ ":" + xpackrPassword);// Keystore 配置builder.put("xpack.security.transport.ssl.keystore.path", certPath);builder.put("xpack.security.transport.ssl.keystore.password", certPassword);// Truststore 配置builder.put("xpack.security.transport.ssl.truststore.path", certPath);builder.put("xpack.security.transport.ssl.truststore.password", certPassword);// 验证模式配置builder.put("xpack.security.transport.ssl.verification_mode", "certificate");// 启用 X-Pack 安全功能builder.put("xpack.security.enabled", true);builder.put("xpack.security.transport.ssl.enabled", true);return builder.build();}/*** 初始化安全TransportClient类*/@Beanpublic TransportClient transportClient() throws Exception {//本地测试用// certPath="D:\\cdms\\es\\elastic-certificates.p12";log.info(">>>>>>>>>>> SecureElasticsearchConfig TransportClient 开始初始化");Settings settings = settings();PreBuiltXPackTransportClient client = new PreBuiltXPackTransportClient(settings);client.addTransportAddress(new TransportAddress(InetAddress.getByName(masterAddress), masterPort));return client;}/***初始化安全ElasticsearchTemplate类* 基于 spring-boot-starter-data*/@Beanpublic ElasticsearchTemplate elasticsearchTemplate(@Autowired TransportClient transportClient) throws Exception {log.info(">>>>>>>>>>> SecureElasticsearchConfig ElasticsearchTemplate 开始初始化");ElasticsearchTemplate secureElasticsearchTemplate;try {secureElasticsearchTemplate = new ElasticsearchTemplate(transportClient);return secureElasticsearchTemplate;} catch (Exception e) {log.error("SecureElasticsearchConfig  初始化ElasticsearchTemplate报错: ", e.getMessage());throw e;}}/*** 初始化安全RestHighLevelClient类* 只支持http  端口: 9200*/@Beanpublic RestHighLevelClient restHighLevelClient() {log.info(">>>>>>>>>>> SecureElasticsearchConfig RestHighLevelClient 开始初始化");final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(xpackUsername, xpackrPassword));RestClientBuilder builder = RestClient.builder(new HttpHost(masterAddress,9200)).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {@Overridepublic HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);}});RestHighLevelClient client = new RestHighLevelClient(builder);//        // 连接延时配置
//        builder.setRequestConfigCallback(requestConfigBuilder -> {
//            requestConfigBuilder.setConnectTimeout(connectTimeOut);
//            requestConfigBuilder.setSocketTimeout(socketTimeOut);
//            requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
//            return requestConfigBuilder;
//        });
//        // 连接数配置
//        builder.setHttpClientConfigCallback(httpClientBuilder -> {
//                    httpClientBuilder.setMaxConnTotal(maxConnectNum);
//                    httpClientBuilder.setMaxConnPerRoute(maxConnectNumPerRoute);
//                    httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
//                    return httpClientBuilder;
//        });return client;}/***初始化安全ElasticsearchRestTemplate类* 基于 spring-boot-starter-data*/@BeanElasticsearchRestTemplate elasticsearchRestTemplate(@Autowired RestHighLevelClient restHighLevelClient) {log.info(">>>>>>>>>>> SecureElasticsearchConfig ElasticsearchRestTemplate 开始初始化");return new ElasticsearchRestTemplate(restHighLevelClient);}}

SecureRestClientConfig

import lombok.Setter;
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.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;import java.util.Arrays;/*** ES 配置 -----Elasticsearch 6.8.23* 通过实现配置配,初始化安全 RestHighLevelClient,ElasticsearchRestTemplate客户端类* 支持x-pack 密码验证*/
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "spring.elasticsearch.rest")
public class SecureRestClientConfig {//端口 ip@Setterprivate String[] hosts = new String[]{};//用户名 elastic@Setterprivate String xpackusername;//用户密码@Setterprivate String xpackpassword;//    // es 连接超时时间
//    private int connectTimeOut;
//    // es socket 连接超时时间
//    private int socketTimeOut;
//    // es 请求超时时间
//    private int connectionRequestTimeOut;
//    // es 最大连接数
//    private int maxConnectNum;
//    // es 每个路由的最大连接数
//    private int maxConnectNumPerRoute;/*** 初始化安全RestHighLevelClient类* 只支持http  端口: 9200*/@Beanpublic RestHighLevelClient restHighLevelClient() {log.info(">>>>>>>>>>> RestClientConfig RestHighLevelClient 开始初始化");HttpHost[] httpHosts = Arrays.stream(hosts).map(x -> {String[] hostInfo = x.split(":");return new HttpHost(hostInfo[0], Integer.parseInt(hostInfo[1]));}).toArray(HttpHost[]::new);log.info("elasticsearch hosts: ", Arrays.toString(httpHosts));final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(xpackusername, xpackpassword));RestClientBuilder builder = null;try {builder = RestClient.builder(httpHosts).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {@Overridepublic HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);}});} catch (Exception e) {log.error("RestClientConfig  初始化RestHighLevelClient报错: ", e.getMessage());throw new RuntimeException(e);}//        // 连接延时配置
//        builder.setRequestConfigCallback(requestConfigBuilder -> {
//            requestConfigBuilder.setConnectTimeout(connectTimeOut);
//            requestConfigBuilder.setSocketTimeout(socketTimeOut);
//            requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
//            return requestConfigBuilder;
//        });
//        // 连接数配置
//        builder.setHttpClientConfigCallback(httpClientBuilder -> {
//                    httpClientBuilder.setMaxConnTotal(maxConnectNum);
//                    httpClientBuilder.setMaxConnPerRoute(maxConnectNumPerRoute);
//                    httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
//                    return httpClientBuilder;
//        });RestHighLevelClient client = new RestHighLevelClient(builder);return client;}@Bean(name = {"elasticsearchOperations", "elasticsearchTemplate"})ElasticsearchRestTemplate elasticsearchRestTemplate(@Autowired RestHighLevelClient restHighLevelClient) {return new ElasticsearchRestTemplate(restHighLevelClient);}
}

6.nacos配置参数

elasticsearch:xpack:username: elasticpassword: escdmskspath: /home/data/eskspwd: master:cluster-name: gz-java-test-laasclusterNodes: master-test-laasaddress: 192.168.2.89port: 9300

7.测试

1.TransportClient

 @Autowiredprivate  TransportClient transportClient;@Testpublic void createIndex_transportClient() {String indexName="lass_test_transportclient";try {CreateIndexRequest request = new CreateIndexRequest(indexName);// 可以在此处添加更多设置,例如映射 (mapping) 和设置 (settings)CreateIndexResponse response = transportClient.admin().indices().create(request).actionGet();if (response.isAcknowledged()) {System.out.println("Index created successfully: " + indexName);} else {System.out.println("Index creation failed: " + indexName);}} catch (Exception e) {System.err.println("Error creating index: " + e.getMessage());}}@Testpublic void addDocuments_transportClient() {String indexName = "lass_test_transportclient";try {String json1 = "{" +"\"user\":\"kimchy\"," +"\"postDate\":\"2013-01-30\"," +"\"message\":\"trying out Elasticsearch\"" +"}";IndexResponse response1 = transportClient.prepareIndex(indexName, "_doc").setSource(json1, XContentType.JSON).get();//            if (response1.status() == RestStatus.CREATED) {
//                System.out.println("Document 1 indexed successfully.");
//            } else {
//                System.out.println("Failed to index Document 1.");
//            }String json2 = "{" +"\"user\":\"Tom\"," +"\"postDate\":\"2024-01-30\"," +"\"message\":\"lass升级 transportClient \"" +"}";transportClient.prepareIndex(indexName, "_doc").setSource(json2, XContentType.JSON).get();} catch (Exception e) {System.err.println("Error adding documents: " + e.getMessage());}}@Testpublic void deleteIndex_transportClient() {String indexName = "lass_test_transportclient";try {DeleteIndexRequest request = new DeleteIndexRequest(indexName);AcknowledgedResponse response = transportClient.admin().indices().delete(request).actionGet();if (response.isAcknowledged()) {System.out.println("Index deleted successfully: " + indexName);} else {System.out.println("Failed to delete index: " + indexName);}} catch (Exception e) {System.err.println("Error deleting index: " + e.getMessage());}}
GET lass_test_transportclient/_search
{"query":{"match_all" : {}}
}

在这里插入图片描述

2.ElasticsearchTemplate

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Document(indexName = "lass_test_people",type = "_doc",shards = 1,replicas = 1)
public class People {@Idprivate String id;// 整个name不被分词,切不创建索引// Keyword表示不被分词@Field(type= FieldType.Keyword,index = false)private String name;// address被ik分词// Text类型的属性才能被分词@Field(type = FieldType.Text)private String address;@Field(type = FieldType.Long,index = false)private int age;}
 @Autowiredprivate ElasticsearchTemplate elasticsearchTemplate;@Testpublic void createIndex_elasticsearchTemplate() {//根据实体类创建索引,boolean result1 = elasticsearchTemplate.createIndex(People.class);System.out.println(result1);//将索引放到软件里面boolean results = elasticsearchTemplate.putMapping(People.class);}@Testpublic void addDocuments_elasticsearchTemplate() {People peo = new People();peo.setId("123");peo.setName("张三");peo.setAddress("北京市海淀区回龙观东大街");peo.setAge(18);IndexQuery query = new IndexQuery();query.setObject(peo);String result = elasticsearchTemplate.index(query);System.out.println(result);}@Testpublic void bulk(){List<IndexQuery> list = new ArrayList<>();// IndexQuery多行写法IndexQuery indexQuery = new IndexQuery();indexQuery.setObject(new People("1", "王五", "北京东城", 12));list.add(indexQuery);// IndexQuery 连缀写法list.add(new IndexQueryBuilder().withObject(new People("2", "赵六", "北京西城", 13)).build());list.add(new IndexQueryBuilder().withObject(new People("3", "吴七", "北京昌平", 14)).build());elasticsearchTemplate.bulkIndex(list);}@Testpublic void deletee_elasticsearchTemplate() {boolean result = elasticsearchTemplate.deleteIndex(People.class);System.out.println(result);}

在这里插入图片描述

3.RestHighLevelClient

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Document(indexName = "lass_test_student",type = AudienceEsConst.DOC, createIndex = false, useServerConfiguration = true)
public class Student {@Idprivate String id;// 整个name不被分词,切不创建索引// Keyword表示不被分词@Field(type= FieldType.Keyword,index = false)private String name;// address被ik分词// Text类型的属性才能被分词@Field(type = FieldType.Text)private String address;@Field(type = FieldType.Long,index = false)private int age;}
 @Autowiredprivate RestHighLevelClient restHighLevelClient;@Testpublic void createIndex_restHighLevelClient() throws IOException {String indexName = "lass_test_resthighlevelclient";XContentBuilder builder = XContentFactory.jsonBuilder();builder.startObject();{builder.field("user", "zhangSan");builder.timeField("postDate", new Date());builder.field("message", "laas 升级 RestHighLevelClient ");}builder.endObject();IndexRequest request = new IndexRequest(indexName, "doc").source(builder);IndexResponse indexResponse = restHighLevelClient.index(request, RequestOptions.DEFAULT);if (indexResponse.status() == RestStatus.CREATED) {System.out.println("Document 1 indexed successfully.");} else {System.out.println("Failed to index Document 1.");}}@Testpublic void addDocuments_restHighLevelClient() {String indexName = "lass_test_resthighlevelclient";try {Map<String, Object> jsonMap = new HashMap<>();jsonMap.put("user", "李四");jsonMap.put("postDate", new Date());jsonMap.put("message", "laas 升级 RestHighLevelClient ");IndexRequest indexRequest = new IndexRequest(indexName,"doc").source(jsonMap);IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);if (indexResponse.status() == RestStatus.CREATED) {System.out.println("Document 1 indexed successfully.");} else {System.out.println("Failed to index Document 1.");}} catch (Exception e) {System.err.println("Error adding documents: " + e.getMessage());}}@Testpublic void deletee_restHighLevelClient() {String indexName = "lass_test_resthighlevelclient";boolean result = elasticsearchTemplate.deleteIndex(indexName);System.out.println(result);}

4.ElasticsearchRestTemplate

 @Autowiredprivate  ElasticsearchRestTemplate  restTemplate;@Testpublic void createIndex_restTemplate() {//根据实体类创建索引,boolean result1 = restTemplate.createIndex(Student.class);System.out.println(result1);//将索引放到软件里面boolean results = restTemplate.putMapping(Student.class);}@Testpublic void addDocuments_restTemplate() {Student student = new Student();student.setId("123");student.setName("张三");student.setAddress("北京市海淀区回龙观东大街");student.setAge(18);IndexQuery query = new IndexQuery();query.setObject(student);String result = restTemplate.index(query);System.out.println(result);}@Testpublic void bulk_restTemplate(){List<IndexQuery> list = new ArrayList<>();// IndexQuery多行写法IndexQuery indexQuery = new IndexQuery();indexQuery.setObject(new Student("1", "王五", "北京东城", 12));list.add(indexQuery);// IndexQuery 连缀写法list.add(new IndexQueryBuilder().withObject(new Student("2", "赵六", "北京西城", 13)).build());list.add(new IndexQueryBuilder().withObject(new Student("3", "吴七", "北京昌平", 14)).build());restTemplate.bulkIndex(list);}@Testpublic void deletee_restTemplate() {boolean result = restTemplate.deleteIndex(Student.class);System.out.println(result);}

相关文章:

ES升级--04--SpringBoot整合Elasticsearch

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 SpringBoot整合Elasticsearch1.建立项目2.Maven 依赖[ES 官方网站&#xff1a;https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.8/index.html](…...

eclipse如何debug

步骤1&#xff1a;双击显示行数的数字来设置断点 步骤2&#xff1a;点击debug 步骤3&#xff1a;在弹出的窗口点击switch 步骤4&#xff1a;就可以调试了&#xff0c;右边是查看数据的&#xff0c;点击上面的图标进行下一步 步骤5&#xff1a;退出debug 步骤6&#xff1a;…...

无人售货机零售业务成功指南:从市场分析到创新策略

在科技驱动的零售新时代&#xff0c;无人售货机作为一种便捷购物解决方案&#xff0c;正逐步兴起&#xff0c;它不仅优化了消费者体验&#xff0c;还显著降低了人力成本&#xff0c;提升了运营效能。开展这项业务前&#xff0c;深入的市场剖析不可或缺&#xff0c;需聚焦消费者…...

开源代码分享(32)-基于改进多目标灰狼算法的冷热电联供型微电网运行优化

参考文献&#xff1a; [1]戚艳,尚学军,聂靖宇,等.基于改进多目标灰狼算法的冷热电联供型微电网运行优化[J].电测与仪表,2022,59(06):12-1952.DOI:10.19753/j.issn1001-1390.2022.06.002. 1.问题背景 针对冷热电联供型微电网运行调度的优化问题&#xff0c;为实现节能减排的目…...

7、架构-架构的安全性

即使只限定在“软件架构设计”这个语境下&#xff0c;系统安全仍然是一 个很大的话题。我们谈论的计算机系统安全&#xff0c;不仅仅是指“防御系统 被黑客攻击”这样狭隘的安全&#xff0c;还至少应包括&#xff08;不限于&#xff09;以下这些问 题的具体解决方案。 认证&am…...

LeetCode题练习与总结:路径总和Ⅱ--113

一、题目描述 给你二叉树的根节点 root 和一个整数目标和 targetSum &#xff0c;找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。 叶子节点 是指没有子节点的节点。 示例 1&#xff1a; 输入&#xff1a;root [5,4,8,11,null,13,4,7,2,null,null,5,1], target…...

Java复数计算

复数在数学、科学或者工程领域是很常用的&#xff0c;可以通过调用Apache Commons Math库来完成&#xff0c;也可以自己手撸。 一、使用Apache Commons Math库 这个库有多个版本&#xff0c;在写这篇文章时&#xff0c;它的最新版是2022年12月19日的4.0-beta1&#xff0c;构建…...

MySQL-事务日志

事务的隔离性由 锁机制 实现 事务的原子性、一致性、隔离性 由事务的 redo日志 和 undo 日志来保证 redo log 称为 重做日志&#xff0c;提供再写入操作&#xff0c;恢复提交事务修改的页操作&#xff0c;用来保证事务的持久性。undo log 称为 回滚日志&#xff0c;回滚行记录…...

PySide6 GUI 学习笔记——常用类及控件使用方法(常用类坐标点QPoint)

控件是PySide设计好的能承载用户输入、输出的小窗体&#xff0c;将多个控件有机整合&#xff0c;能形成用户所需要的界面。而每一个控件&#xff0c;都有属于自己的属性、方法、信号、槽函数和事件&#xff08;event&#xff09;&#xff0c;且控件与控件之间又有继承关系。 G…...

算法练习——字符串

一确定字符串是否包含唯一字符 1.1涉及知识点 c的输入输出语法 cin>>s; cout<<"NO"; 如何定义字符串 切记&#xff1a;在[]中必须加数字——字符串最大长度&#xff0c;不然编译不通过 char s[101]; 如何获取字符串长度 char s[101];cin>>s;i…...

Flutter 中的 SliverOverlapInjector 小部件:全面指南

Flutter 中的 SliverOverlapInjector 小部件&#xff1a;全面指南 Flutter 是一个功能丰富的 UI 框架&#xff0c;由 Google 开发&#xff0c;允许开发者使用 Dart 语言构建跨平台的移动、Web 和桌面应用。在 Flutter 的滚动视图系统中&#xff0c;SliverOverlapInjector 是一…...

7个Python爬虫入门小案例

大家好&#xff0c;随着互联网的快速发展&#xff0c;数据成为了新时代的石油。Python作为一种高效、易学的编程语言&#xff0c;在数据采集领域有着广泛的应用。本文将详细讲解Python爬虫的原理、常用库以及实战案例&#xff0c;帮助读者掌握爬虫技能。 一、爬虫原理 爬虫&a…...

linux 利用 ~$() 构造数字

2024.6.1 题目 <?php //flag in 12.php error_reporting(0); if(isset($_GET[x])){$x $_GET[x];if(!preg_match("/[a-z0-9;|#\"%&\x09\x0a><.,?*\-\\[\]]/i", $x)){system("cat ".$x.".php");} }else{highlight_file(__F…...

七大获取免费https的方式

想要实现https访问最简单有效的的方法就是安装SSL证书。只要证书正常安装上以后&#xff0c;浏览器就不会出现网站不安全提示或者访问被拦截的情况。下面我来教大家怎么去获取免费的SSL证书&#xff0c;又如何安装证书实现https访问。 一、选择免费SSL证书提供商 有多家机构提…...

JVM(Java虚拟机)笔记

面试常见&#xff1a; 请你谈谈你对JVM的理解?java8虚拟机和之前的变化更新?什么是OOM&#xff0c;什么是栈溢出StackOverFlowError? 怎么分析?JVM的常用调优参数有哪些?内存快照如何抓取&#xff1f;怎么分析Dump文件&#xff1f;谈谈JVM中&#xff0c;类加载器你的认识…...

秒杀基本功能开发(显示商品列表和商品详情)

文章目录 1.数据库表设计1.商品表2.秒杀商品表3.修改一下秒杀时间为今天到明天 2.pojo和vo编写1.com/sxs/seckill/pojo/Goods.java2.com/sxs/seckill/pojo/SeckillGoods.java3.com/sxs/seckill/vo/GoodsVo.java 3.Mapper编写1.GoodsMapper.java2.GoodsMapper.xml3.分别编写Seck…...

centos 记录用户登陆ip和执行命令

centos 记录用户登陆ip和执行命令 在/etc/profile 文件末尾添加如下代码&#xff1a; #!/bin/bash USER_IPwho -u am i 2>/dev/null | awk {print $NF} | sed -e s/[()]//g HISTDIR/usr/share/.history if [ -z "$USER_IP" ]; then USER_IPhostname fi…...

JZ2440笔记:DM9000C网卡驱动

在厂家提供的dm9dev9000c.c上修改&#xff0c; 1、注释掉#ifdef MODULE #endif 2、用模块化函数修饰入口出口函数 3、在dm9000c_init入口函数&#xff0c;增加iobase (int)ioremap(0x20000000,1024);irq IRQ_EINT7; 4、一路进入&#xff0c;在dmfe_probe1中注释掉if((db…...

【数据结构】二叉树:简约和复杂的交织之美

专栏引入&#xff1a; 哈喽大家好&#xff0c;我是野生的编程萌新&#xff0c;首先感谢大家的观看。数据结构的学习者大多有这样的想法&#xff1a;数据结构很重要&#xff0c;一定要学好&#xff0c;但数据结构比较抽象&#xff0c;有些算法理解起来很困难&#xff0c;学的很累…...

信号稳定,性能卓越!德思特礁鲨系列MiMo天线正式发布!

作者介绍 礁鲨系列天线&#xff0c;以其独特的外观设计和强大的性能&#xff0c;成为德思特Panorama智能天线家族的最新成员。这款天线不仅稳定提供5G、WIFI和GNSS信号&#xff0c;更能在各类复杂环境中展现出卓越的性能。它的设计灵感来源于海洋中的礁鲨&#xff0c;象征着力量…...

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇&#xff0c;在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下&#xff1a; 【Note】&#xff1a;如果你已经完成安装等操作&#xff0c;可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作&#xff0c;重…...

CTF show Web 红包题第六弹

提示 1.不是SQL注入 2.需要找关键源码 思路 进入页面发现是一个登录框&#xff0c;很难让人不联想到SQL注入&#xff0c;但提示都说了不是SQL注入&#xff0c;所以就不往这方面想了 ​ 先查看一下网页源码&#xff0c;发现一段JavaScript代码&#xff0c;有一个关键类ctfs…...

<6>-MySQL表的增删查改

目录 一&#xff0c;create&#xff08;创建表&#xff09; 二&#xff0c;retrieve&#xff08;查询表&#xff09; 1&#xff0c;select列 2&#xff0c;where条件 三&#xff0c;update&#xff08;更新表&#xff09; 四&#xff0c;delete&#xff08;删除表&#xf…...

Admin.Net中的消息通信SignalR解释

定义集线器接口 IOnlineUserHub public interface IOnlineUserHub {/// 在线用户列表Task OnlineUserList(OnlineUserList context);/// 强制下线Task ForceOffline(object context);/// 发布站内消息Task PublicNotice(SysNotice context);/// 接收消息Task ReceiveMessage(…...

uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖

在前面的练习中&#xff0c;每个页面需要使用ref&#xff0c;onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入&#xff0c;需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...

大模型多显卡多服务器并行计算方法与实践指南

一、分布式训练概述 大规模语言模型的训练通常需要分布式计算技术,以解决单机资源不足的问题。分布式训练主要分为两种模式: 数据并行:将数据分片到不同设备,每个设备拥有完整的模型副本 模型并行:将模型分割到不同设备,每个设备处理部分模型计算 现代大模型训练通常结合…...

零基础设计模式——行为型模式 - 责任链模式

第四部分&#xff1a;行为型模式 - 责任链模式 (Chain of Responsibility Pattern) 欢迎来到行为型模式的学习&#xff01;行为型模式关注对象之间的职责分配、算法封装和对象间的交互。我们将学习的第一个行为型模式是责任链模式。 核心思想&#xff1a;使多个对象都有机会处…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...

JAVA后端开发——多租户

数据隔离是多租户系统中的核心概念&#xff0c;确保一个租户&#xff08;在这个系统中可能是一个公司或一个独立的客户&#xff09;的数据对其他租户是不可见的。在 RuoYi 框架&#xff08;您当前项目所使用的基础框架&#xff09;中&#xff0c;这通常是通过在数据表中增加一个…...

springboot整合VUE之在线教育管理系统简介

可以学习到的技能 学会常用技术栈的使用 独立开发项目 学会前端的开发流程 学会后端的开发流程 学会数据库的设计 学会前后端接口调用方式 学会多模块之间的关联 学会数据的处理 适用人群 在校学生&#xff0c;小白用户&#xff0c;想学习知识的 有点基础&#xff0c;想要通过项…...