【Elasticsearch入门到落地】12、索引库删除判断以及文档增删改查

接上篇《11、RestClient初始化索引库》
上一篇我们完成了使用RestHighLevelClient创建索引库的代码实现,本篇将讲解如何判断索引库是否存在并删除它,以及如何对索引库中的文档进行增删改查操作。

一、索引库判断与删除

在操作索引库时,有时需要先判断索引库是否存在,若存在则进行删除操作。以下是具体的实现代码:

1. 判断索引库是否存在

@Test
void testExistsIndex() throws IOException {// 1. 准备RequestGetIndexRequest request = new GetIndexRequest("hotel");// 2. 发送请求boolean isExists = client.indices().exists(request, RequestOptions.DEFAULT);System.out.println(isExists ? "索引库存在" : "索引库不存在");
}

代码解析:
GetIndexRequest 是 Elasticsearch 提供的用于判断索引库是否存在的请求类。
调用 client.indices().exists() 方法发送请求,并返回一个布尔值,表示索引库是否存在。
异常处理:如果索引库名称格式错误,可能会抛出 IllegalArgumentException。

2. 删除索引库

@Test
void testDeleteIndex() throws IOException {// 1. 准备RequestDeleteIndexRequest request = new DeleteIndexRequest("hotel");// 2. 发送请求client.indices().delete(request, RequestOptions.DEFAULT);System.out.println("索引库删除成功");
}

代码解析:
DeleteIndexRequest 是 Elasticsearch 提供的用于删除索引库的请求类。
调用 client.indices().delete() 方法发送请求。
异常处理:如果索引库不存在,可能会抛出 IndexNotFoundException。

二、文档的增删改查

1. 添加文档

@Test
void testAddDocument() throws IOException {// 1. 查询数据库hotel数据Hotel hotel = hotelService.getById(61083L);// 2. 转换为HotelDocHotelDoc hotelDoc = new HotelDoc(hotel);// 3. 转JSONString json = JSON.toJSONString(hotelDoc);// 1. 准备RequestIndexRequest request = new IndexRequest("hotel").id(hotelDoc.getId().toString());// 2. 准备请求参数DSL,其实就是文档的JSON字符串request.source(json, XContentType.JSON);// 3. 发送请求client.index(request, RequestOptions.DEFAULT);System.out.println("文档添加成功");
}

代码解析:
IndexRequest 是 Elasticsearch 提供的用于添加文档的请求类。
调用 client.index() 方法发送请求。
异常处理:如果索引库不存在,可能会抛出 IndexNotFoundException。Hotel和HotelDoc实体代码:

package cn.itcast.hotel.pojo;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;@Data
@TableName("tb_hotel")
public class Hotel {@TableId(type = IdType.INPUT)private Long id;private String name;private String address;private Integer price;private Integer score;private String brand;private String city;private String starName;private String business;private String longitude;private String latitude;private String pic;
}
package cn.itcast.hotel.pojo;import lombok.Data;
import lombok.NoArgsConstructor;@Data
@NoArgsConstructor
public class HotelDoc {private Long id;private String name;private String address;private Integer price;private Integer score;private String brand;private String city;private String starName;private String business;private String location;private String pic;private Object distance;private Boolean isAD;public HotelDoc(Hotel hotel) {this.id = hotel.getId();this.name = hotel.getName();this.address = hotel.getAddress();this.price = hotel.getPrice();this.score = hotel.getScore();this.brand = hotel.getBrand();this.city = hotel.getCity();this.starName = hotel.getStarName();this.business = hotel.getBusiness();this.location = hotel.getLatitude() + ", " + hotel.getLongitude();this.pic = hotel.getPic();}
}

2. 根据ID查询文档

@Test
void testGetDocumentById() throws IOException {// 1. 准备Request      // GET /hotel/_doc/{id}GetRequest request = new GetRequest("hotel", "61083");// 2. 发送请求GetResponse response = client.get(request, RequestOptions.DEFAULT);// 3. 解析响应结果String json = response.getSourceAsString();HotelDoc hotelDoc = JSON.parseObject(json, HotelDoc.class);System.out.println("hotelDoc = " + hotelDoc);
}

代码解析:
GetRequest 是 Elasticsearch 提供的用于查询文档的请求类。
调用 client.get() 方法发送请求,并返回 GetResponse 对象。
使用 response.getSourceAsString() 获取文档的 JSON 字符串。
异常处理:如果文档不存在,response.isExists() 将返回 false。

3. 根据ID删除文档

@Test
void testDeleteDocumentById() throws IOException {// 1. 准备Request      // DELETE /hotel/_doc/{id}DeleteRequest request = new DeleteRequest("hotel", "61083");// 2. 发送请求client.delete(request, RequestOptions.DEFAULT);System.out.println("文档删除成功");
}

代码解析:
DeleteRequest 是 Elasticsearch 提供的用于删除文档的请求类。
调用 client.delete() 方法发送请求。
异常处理:如果文档不存在,可能会抛出 DocumentMissingException。

4. 根据ID更新文档

@Test
void testUpdateById() throws IOException {// 1. 准备RequestUpdateRequest request = new UpdateRequest("hotel", "61083");// 2. 准备参数request.doc("price", "870");// 3. 发送请求client.update(request, RequestOptions.DEFAULT);System.out.println("文档更新成功");
}

代码解析:
UpdateRequest 是 Elasticsearch 提供的用于更新文档的请求类。
调用 request.doc() 方法设置更新的字段和值。
调用 client.update() 方法发送请求。
异常处理:如果文档不存在,可能会抛出 DocumentMissingException。

5. 批量操作

@Test
void testBulkRequest() throws IOException {// 查询所有的酒店数据List<Hotel> list = hotelService.list();// 1. 准备RequestBulkRequest request = new BulkRequest();// 2. 准备参数for (Hotel hotel : list) {// 2.1. 转为HotelDocHotelDoc hotelDoc = new HotelDoc(hotel);// 2.2. 转jsonString json = JSON.toJSONString(hotelDoc);// 2.3. 添加请求request.add(new IndexRequest("hotel").id(hotel.getId().toString()).source(json, XContentType.JSON));}// 3. 发送请求client.bulk(request, RequestOptions.DEFAULT);System.out.println("批量操作成功");
}

代码解析:
BulkRequest 是 Elasticsearch 提供的用于批量操作的请求类。
调用 request.add() 方法添加多个子请求(如添加、更新、删除)。
调用 client.bulk() 方法发送批量请求。
异常处理:如果批量操作中某个请求失败,可能会抛出 BulkItemResponse.Failure 异常。

三、什么是 RequestOptions.DEFAULT?

RequestOptions.DEFAULT 是 Elasticsearch 提供的默认请求选项,表示使用默认的配置参数发送请求。例如:

●默认的超时时间。
●默认的认证信息(如果需要)。
●默认的请求头信息。

如果需要自定义请求选项,可以通过 RequestOptions.Builder 创建,例如:

RequestOptions options = RequestOptions.DEFAULT.toBuilder().addHeader("Custom-Header", "value").build();

四、完整测试类

package cn.itcast.hotel;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.IOException;
import java.util.List;@SpringBootTest
class HotelDocumentTest {private RestHighLevelClient client;@Autowiredprivate IHotelService hotelService;@Testvoid testAddDocument() throws IOException {// 1.查询数据库hotel数据Hotel hotel = hotelService.getById(61083L);// 2.转换为HotelDocHotelDoc hotelDoc = new HotelDoc(hotel);// 3.转JSONString json = JSON.toJSONString(hotelDoc);// 1.准备RequestIndexRequest request = new IndexRequest("hotel").id(hotelDoc.getId().toString());// 2.准备请求参数DSL,其实就是文档的JSON字符串request.source(json, XContentType.JSON);// 3.发送请求client.index(request, RequestOptions.DEFAULT);}@Testvoid testGetDocumentById() throws IOException {// 1.准备Request      // GET /hotel/_doc/{id}GetRequest request = new GetRequest("hotel", "61083");// 2.发送请求GetResponse response = client.get(request, RequestOptions.DEFAULT);// 3.解析响应结果String json = response.getSourceAsString();HotelDoc hotelDoc = JSON.parseObject(json, HotelDoc.class);System.out.println("hotelDoc = " + hotelDoc);}@Testvoid testDeleteDocumentById() throws IOException {// 1.准备Request      // DELETE /hotel/_doc/{id}DeleteRequest request = new DeleteRequest("hotel", "61083");// 2.发送请求client.delete(request, RequestOptions.DEFAULT);}@Testvoid testUpdateById() throws IOException {// 1.准备RequestUpdateRequest request = new UpdateRequest("hotel", "61083");// 2.准备参数request.doc("price", "870");// 3.发送请求client.update(request, RequestOptions.DEFAULT);}@Testvoid testBulkRequest() throws IOException {// 查询所有的酒店数据List<Hotel> list = hotelService.list();// 1.准备RequestBulkRequest request = new BulkRequest();// 2.准备参数for (Hotel hotel : list) {// 2.1.转为HotelDocHotelDoc hotelDoc = new HotelDoc(hotel);// 2.2.转jsonString json = JSON.toJSONString(hotelDoc);// 2.3.添加请求request.add(new IndexRequest("hotel").id(hotel.getId().toString()).source(json, XContentType.JSON));}// 3.发送请求client.bulk(request, RequestOptions.DEFAULT);}@BeforeEachvoid setUp() {client = new RestHighLevelClient(RestClient.builder(HttpHost.create("http://192.168.2.129:9200")));}@AfterEachvoid tearDown() throws IOException {client.close();}
}        

五、数据库查询机制解释

这里给不了解mybatis-plus-extension-3.4.2的同学解释一下,为什么直接用hotelService.getById就可以查询数据库数据了。首先看一下hotelService和其实现类代码:

package cn.itcast.hotel.service;import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import com.baomidou.mybatisplus.extension.service.IService;public interface IHotelService extends IService<Hotel> {PageResult search(RequestParams params);
}
package cn.itcast.hotel.service.impl;import cn.itcast.hotel.mapper.HotelMapper;
import cn.itcast.hotel.pojo.Hotel;
import cn.itcast.hotel.pojo.HotelDoc;
import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.IHotelService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;@Slf4j
@Service
public class HotelService extends ServiceImpl<HotelMapper, Hotel> implements IHotelService {@Autowiredprivate RestHighLevelClient restHighLevelClient;@Overridepublic PageResult search(RequestParams params) {try {// 1.准备RequestSearchRequest request = new SearchRequest("hotel");// 2.准备请求参数// 2.1.querybuildBasicQuery(params, request);// 2.2.分页int page = params.getPage();int size = params.getSize();request.source().from((page - 1) * size).size(size);// 2.3.距离排序String location = params.getLocation();if (StringUtils.isNotBlank(location)) {request.source().sort(SortBuilders.geoDistanceSort("location", new GeoPoint(location)).order(SortOrder.ASC).unit(DistanceUnit.KILOMETERS));}// 3.发送请求SearchResponse response = restHighLevelClient.search(request, RequestOptions.DEFAULT);// 4.解析响应return handleResponse(response);} catch (IOException e) {throw new RuntimeException("搜索数据失败", e);}}private void buildBasicQuery(RequestParams params, SearchRequest request) {// 1.准备Boolean查询BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();// 1.1.关键字搜索,match查询,放到must中String key = params.getKey();if (StringUtils.isNotBlank(key)) {// 不为空,根据关键字查询boolQuery.must(QueryBuilders.matchQuery("all", key));} else {// 为空,查询所有boolQuery.must(QueryBuilders.matchAllQuery());}// 1.2.品牌String brand = params.getBrand();if (StringUtils.isNotBlank(brand)) {boolQuery.filter(QueryBuilders.termQuery("brand", brand));}// 1.3.城市String city = params.getCity();if (StringUtils.isNotBlank(city)) {boolQuery.filter(QueryBuilders.termQuery("city", city));}// 1.4.星级String starName = params.getStarName();if (StringUtils.isNotBlank(starName)) {boolQuery.filter(QueryBuilders.termQuery("starName", starName));}// 1.5.价格范围Integer minPrice = params.getMinPrice();Integer maxPrice = params.getMaxPrice();if (minPrice != null && maxPrice != null) {maxPrice = maxPrice == 0 ? Integer.MAX_VALUE : maxPrice;boolQuery.filter(QueryBuilders.rangeQuery("price").gte(minPrice).lte(maxPrice));}// 2.算分函数查询FunctionScoreQueryBuilder functionScoreQuery = QueryBuilders.functionScoreQuery(boolQuery, // 原始查询,boolQuerynew FunctionScoreQueryBuilder.FilterFunctionBuilder[]{ // function数组new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("isAD", true), // 过滤条件ScoreFunctionBuilders.weightFactorFunction(10) // 算分函数)});// 3.设置查询条件request.source().query(functionScoreQuery);}private PageResult handleResponse(SearchResponse response) {SearchHits searchHits = response.getHits();// 4.1.总条数long total = searchHits.getTotalHits().value;// 4.2.获取文档数组SearchHit[] hits = searchHits.getHits();// 4.3.遍历List<HotelDoc> hotels = new ArrayList<>(hits.length);for (SearchHit hit : hits) {// 4.4.获取sourceString json = hit.getSourceAsString();// 4.5.反序列化,非高亮的HotelDoc hotelDoc = JSON.parseObject(json, HotelDoc.class);// 4.6.处理高亮结果// 1)获取高亮mapMap<String, HighlightField> map = hit.getHighlightFields();if (map != null && !map.isEmpty()) {// 2)根据字段名,获取高亮结果HighlightField highlightField = map.get("name");if (highlightField != null) {// 3)获取高亮结果字符串数组中的第1个元素String hName = highlightField.getFragments()[0].toString();// 4)把高亮结果放到HotelDoc中hotelDoc.setName(hName);}}// 4.8.排序信息Object[] sortValues = hit.getSortValues();if (sortValues.length > 0) {hotelDoc.setDistance(sortValues[0]);}// 4.9.放入集合hotels.add(hotelDoc);}return new PageResult(total, hotels);}
}

然后是HotelMapper的代码:

package cn.itcast.hotel.mapper;import cn.itcast.hotel.pojo.Hotel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;public interface HotelMapper extends BaseMapper<Hotel> {
}

这里为什么我们不需要在hotelService的实现类中再去写HotelMapper的getById代码,类似如下:

@Service
public class HotelServiceImpl implements HotelService {@Autowiredprivate HotelMapper hotelMapper;@Testpublic void testSelectById(Serializable id) {Hotel hotel = hotelMapper.selectById(id);System.out.println(hotel);}
}

而是直接在其他测试类中直接可以调用hotelService.getById呢?这是因为当HotelService同时继承ServiceImpl<HotelMapper, Hotel> 并实现 HotelService接口时,大部分基础CRUD操作的实现确实不需要再手动编写了。原因如下:
​​1、ServiceImpl已提供默认实现​​
ServiceImpl是MyBatis-Plus提供的通用服务实现类,它已经实现了IService接口中的所有基础方法(如save、remove、update、getById、list等)。这些方法通过泛型HotelMapper直接调用底层Mapper的CRUD操作。
​2、继承关系的作用​​
IHotelService接口继承IService<Hotel>:定义了服务层的契约方法(包括MyBatis-Plus提供的通用方法和自定义业务方法)。
ServiceImpl<HotelMapper, Hotel>:通过泛型绑定了具体的Mapper(HotelMapper)和实体类(Hotel),并自动注入baseMapper(即HotelMapper实例),直接复用其CRUD能力。
​​3、无需重复编写的场景​​
如果业务仅需基础增删改查(如getById、save等),直接继承ServiceImpl后,这些方法已默认实现,无需在 HotelServiceImpl中重写。例如:

@Service
public class HotelServiceImpl extends ServiceImpl<HotelMapper, Hotel> implements HotelService {// 无需实现 getById(),直接继承父类的默认实现
}

​4、仍需自定义的场景​​
若需扩展复杂业务逻辑(如多表关联查询、特殊条件更新),仍需在HotelServiceImpl中重写或新增方法。例如:

@Override
public Hotel getHotelWithOtherCondition(String condition) {// 自定义逻辑需手动实现
}

​​总结​​:继承ServiceImpl后,基础CRUD方法由MyBatis-Plus自动提供,开发者只需关注自定义业务逻辑即可,这是MyBatis-Plus设计的重要优势——减少重复代码,提升开发效率。

六、总结

1. 新增文档 (Create)

​​Request:​​ IndexRequest
​​(1)参数:​​
索引名 (必填)
文档ID (可选,不填会自动生成)
文档内容 (JSON格式)
(2)请求创建代码

IndexRequest request = new IndexRequest("索引名").id("文档ID")  // 可选.source(JSON数据, XContentType.JSON);

(3)执行代码

client.index(request, RequestOptions.DEFAULT);

2. 查询文档 (Read)

​​Request:​​ GetRequest
​​(1)参数:​​
索引名 (必填)
文档ID (必填)
(2)请求创建代码

GetRequest request = new GetRequest("索引名", "文档ID");

(3)执行代码

client.get(request, RequestOptions.DEFAULT);

3. 更新文档 (Update)

​​Request:​​ UpdateRequest
​​(1)参数:​​
索引名 (必填)
文档ID (必填)
要更新的字段 (Map或键值对形式)
(2)请求创建代码

UpdateRequest request = new UpdateRequest("索引名", "文档ID").doc("字段1", "值1", "字段2", "值2");  // 部分更新

(3)执行代码

client.update(request, RequestOptions.DEFAULT);

4. 删除文档 (Delete)

​​Request:​​ DeleteRequest
​​(1)参数:​​
索引名 (必填)
文档ID (必填)
(2)请求创建代码

DeleteRequest request = new DeleteRequest("索引名", "文档ID");

(3)执行代码

client.delete(request, RequestOptions.DEFAULT);

5. 批量操作 (Bulk)

​​Request:​​ BulkRequest
​​(1)参数:​​
可添加多个Index/Update/Delete请求
(2)请求创建代码

BulkRequest request = new BulkRequest().add(new IndexRequest(...))  // 批量新增.add(new UpdateRequest(...)) // 批量更新.add(new DeleteRequest(...));// 批量删除

(3)执行代码

//client为RestHighLevelClient
client.bulk(request, RequestOptions.DEFAULT);    

下一篇我们将讲解如何使用Elasticsearch的查询DSL实现复杂的搜索功能。

转载请注明出处:https://blog.csdn.net/acmman/article/details/147719492

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

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

相关文章

国联股份卫多多与国术科技签署战略合作协议

4月30日&#xff0c;国术科技&#xff08;北京&#xff09;有限公司&#xff08;以下简称“国术科技”&#xff09;营销中心总经理 王志广、贾雷一行到访国联股份卫多多&#xff0c;同卫多多/纸多多副总裁、产发部总经理段任飞&#xff0c;卫多多机器人产业链总经理桂林展开深入…

linux mcelog inject注入

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、mce inject是什么&#xff1f;二、使用步骤1.操作示例 总结 前言 记录下mce 触发inject和内核打印 内核版本&#xff1a; 5.10.92 开启选项&#xff1a;…

Nginx安全防护与HTTPS部署实战

目录 一&#xff1a;核心安全配置 1&#xff1a;编译安装nginx &#xff08;1&#xff09;安装支持软件 &#xff08;2&#xff09;创建运行用户&#xff0c;组和日志目录 &#xff08;3&#xff09;编译安装nginx &#xff08;4&#xff09;添加nginx系统服务 2&#xf…

DeepSeek API接口调用示例(开发语言C#,替换其中key值为自己的key值即可)

示例&#xff1a; DeepSeek官方接口说明文档&#xff1a;对话补全 | DeepSeek API Docs 官网暂未提供C#代码实现&#xff1a;&#xff08;以下为根据CURL接口C#代码调用&#xff09; using System; using System.Collections.Generic; using System.Linq; using System.Text; …

一文掌握 LVGL 9 的源码目录结构

文章目录 &#x1f4c2; 一文掌握 LVGL 9 的源码目录结构&#x1f9ed; 顶层目录概览&#x1f4c1; 1. src/ — LVGL 的核心源码&#xff08;&#x1f525;重点&#xff09;&#x1f4c1; 2. examples/ — API 示例&#x1f4c1; 3. demos/ — 综合演示项目&#x1f4c1; 4. do…

大物重修之浅显知识点

第一章 质点运动学 例1 知识点公式如下&#xff1a; 例2 例3 例4 例5 例6 第四章 刚体的转动 例1 例2 例3 例4 例5 例6 第五章 简谐振动 例1 例2 例3 第六章 机械波 第八章 热力学基础 第九章 静电场 第十一章 恒定磁场…

安卓的systemservice 、systemserver、systemservicemanage和servicemanage用法

以下是对安卓中SystemService、SystemServer、SystemServiceManager和ServiceManager的讲解和区别&#xff1a; SystemService 定义&#xff1a;是Framework中对应特定功能的服务&#xff0c;供其他模块和App调用&#xff0c;如BatteryService、PowerManagerService等。它是所…

LDO与DCDC总结

目录 1. 工作原理 2. 性能对比 3. 选型关键因素 4. 典型应用 总结 1. 工作原理 LDO LDO通过线性调节方式实现降压&#xff0c;输入电压需略高于输出电压&#xff08;压差通常为0.2-2V&#xff09;&#xff0c;利用内部PMOS管或PNP三极管调整压差以稳定输出电压。其结构简单…

系统的从零开始学习电子的相关知识,该如何规划?

一、基础理论奠基&#xff08;6-12个月&#xff09; 1.1 数学与物理基础 核心内容&#xff1a; 微积分与线性代数&#xff08;高频电路建模必备&#xff09;复变函数与概率论&#xff08;信号处理与通信系统基础&#xff09;电磁场基础&#xff08;麦克斯韦方程组的物理意义&…

(x ^ 2 + 2y − 1) ^ 3 − x ^ 2 * y ^ 3 = 1

二元高次方程 EquationSolver20250509.java package math;import org.apache.commons.math3.analysis.MultivariateFunction; import org.apache.commons.math3.optim.InitialGuess; import org.apache.commons.math3.optim.MaxEval; import org.apache.commons.math3.optim.P…

解决应用程序在JAR包中运行时无法读取类路径下文件的问题

问题情景 java应用程序在IDE运行正常&#xff0c;打成jar包后执行却发生异常&#xff1a; java.io.FileNotFoundException: class path resource [cert/sync_signer_pri_test.key] cannot be resolved to absolute file path because it does not reside in the file system:…

Mac QT水平布局和垂直布局

首先上代码 #include "mainwindow.h" #include "ui_mainwindow.h" #include <QPushButton> #include<QVBoxLayout>//垂直布局 #include<QHBoxLayout>//水平布局头文件 MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), …

uniapp中用canvas绘制简单柱形图,小容量,不用插件——简单使用canvas

uniapp中用canvas绘制简单柱形图&#xff0c;小容量&#xff0c;不用插件——简单使用canvas 完整代码 <template><view><!-- 学习数据 --><!-- 头部选项卡 --><view class"navTab"><view :class"listIndexi?activite:"…

[Unity]-[UI]-[Image] 关于UI精灵图资源导入设置的详细解释

Unity UI Sprite UI资源导入详解图片导入项目Texture TypeTexture ShapeAdvanced Setting 高级设置 图片设置案例常见细节问题 知识点详解来源 UI资源导入详解 Unity中的UI资源有图片、矢量图、字体、预制体、图集、动画等等资源。 这其中图片是最重要以及最基础的资源组成&a…

【递归、搜索和回溯】递归、搜索和回溯介绍及递归类算法例题

个人主页 &#xff1a; zxctscl 专栏 【C】、 【C语言】、 【Linux】、 【数据结构】、 【算法】 如有转载请先通知 文章目录 递归、搜索和回溯递归搜索VS 深度优先遍历 VS 深度优先搜索 VS 宽度优先遍历 VS 宽度优先搜索 VS 暴搜回溯与剪枝 1 面试题 08.06. 汉诺塔问题1.1 分析…

快手618购物节招商启动,国补可叠加跨店满减等大促补贴

5月8日&#xff0c;快手电商在杭州召开「破峰2025」商家大会。会上&#xff0c;快手电商C端产品负责人孔慧介绍了快手电商全域经营年度策略以及新锐商家长效经营方法论&#xff0c;并宣布快手618购物节招商报名正式启动。 信任社区生态是快手电商发展的基石&#xff0c;2025年…

AI服务器通常会运用在哪些场景当中?

人工智能行业作为现代科技的杰出代表&#xff0c;在多个领域当中发展其强大的应用能力和价值&#xff0c;随之&#xff0c;AI服务器也在各个行业中日益显现出来&#xff0c;为各个行业提供了强大的计算能力和处理能力&#xff0c;帮助企业处理复杂的大规模数据&#xff0c;本文…

MySQL高可用方案全攻略:选型指南与AI运维实践

MySQL高可用方案全攻略:选型指南与AI运维实践 引言:当数据库成为业务生命线 在数字化时代,数据库就是企业的"心脏"。一次数据库宕机可能导致: 电商网站每秒损失上万元订单游戏公司遭遇玩家大规模流失金融系统引发连锁反应本文将为你揭秘: MySQL主流高可用方案…

电位器如何接入西门子PLC的模拟量输入

1.设计思考 我现在手上有一个三线10kΩ的滑动变阻器&#xff0c;想让其当作模拟量接入西门子PLC中&#xff0c;外部改变电阻&#xff0c;PLC程序中能看到对应的阻值或电压&#xff0c;这样可以练习模拟量输入这个知识点&#xff01; 2.了解模拟量的种类 模拟量一般有电压型和…

MongoDB培训文档大纲(超详细)

第一章&#xff1a;引言 1.1 什么是MongoDB&#xff1f; 定义&#xff1a; MongoDB 是一个开源的 NoSQL 数据库&#xff0c;基于文档模型存储数据。它允许使用 JSON 格式&#xff08;更具体地说是 BSON&#xff09;来存储结构化和半结构化数据。MongoDB 是一个高性能、可扩展且…