樹型表查詢方法 —— SQL遞歸

目錄

引言:

自鏈接查詢:?

?遞歸查詢:?

編寫service接口實現:


引言:

看下圖,這是 course_category 課程分類表的結構:

這張表是一個樹型結構,通過父結點id將各元素組成一個樹。

我們可以看下該表的數據,下圖是一部分數據:

現在的需求是需要在內容管理服務中編寫一個接口讀取該課程分類表的數據,組成一個樹型結構返回給前端。


樹形表的根本在于它有一個 parentid 字段,而這個字段是為了記錄當前結點的父節點的 id 值。所以每一個樹型表都會有一個這樣的字段。

通過查閱接口文檔,此接口要返回全部課程分類,以樹型結構返回,如下所示:

 [{"childrenTreeNodes" : [{"childrenTreeNodes" : null,"id" : "1-1-1","isLeaf" : null,"isShow" : null,"label" : "HTML/CSS","name" : "HTML/CSS","orderby" : 1,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-2","isLeaf" : null,"isShow" : null,"label" : "JavaScript","name" : "JavaScript","orderby" : 2,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-3","isLeaf" : null,"isShow" : null,"label" : "jQuery","name" : "jQuery","orderby" : 3,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-4","isLeaf" : null,"isShow" : null,"label" : "ExtJS","name" : "ExtJS","orderby" : 4,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-5","isLeaf" : null,"isShow" : null,"label" : "AngularJS","name" : "AngularJS","orderby" : 5,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-6","isLeaf" : null,"isShow" : null,"label" : "ReactJS","name" : "ReactJS","orderby" : 6,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-7","isLeaf" : null,"isShow" : null,"label" : "Bootstrap","name" : "Bootstrap","orderby" : 7,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-8","isLeaf" : null,"isShow" : null,"label" : "Node.js","name" : "Node.js","orderby" : 8,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-9","isLeaf" : null,"isShow" : null,"label" : "Vue","name" : "Vue","orderby" : 9,"parentid" : "1-1"},{"childrenTreeNodes" : null,"id" : "1-1-10","isLeaf" : null,"isShow" : null,"label" : "其它","name" : "其它","orderby" : 10,"parentid" : "1-1"}],"id" : "1-1","isLeaf" : null,"isShow" : null,"label" : "前端開發","name" : "前端開發","orderby" : 1,"parentid" : "1"},{"childrenTreeNodes" : [{"childrenTreeNodes" : null,"id" : "1-2-1","isLeaf" : null,"isShow" : null,"label" : "微信開發","name" : "微信開發","orderby" : 1,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-2","isLeaf" : null,"isShow" : null,"label" : "iOS","name" : "iOS","orderby" : 2,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-3","isLeaf" : null,"isShow" : null,"label" : "手游開發","name" : "手游開發","orderby" : 3,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-4","isLeaf" : null,"isShow" : null,"label" : "Swift","name" : "Swift","orderby" : 4,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-5","isLeaf" : null,"isShow" : null,"label" : "Android","name" : "Android","orderby" : 5,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-6","isLeaf" : null,"isShow" : null,"label" : "ReactNative","name" : "ReactNative","orderby" : 6,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-7","isLeaf" : null,"isShow" : null,"label" : "Cordova","name" : "Cordova","orderby" : 7,"parentid" : "1-2"},{"childrenTreeNodes" : null,"id" : "1-2-8","isLeaf" : null,"isShow" : null,"label" : "其它","name" : "其它","orderby" : 8,"parentid" : "1-2"}],"id" : "1-2","isLeaf" : null,"isShow" : null,"label" : "移動開發","name" : "移動開發","orderby" : 2,"parentid" : "1"}]

而上邊的數據格式是一個數組結構,數組的元素即為分類信息,分類信息設計兩級分類,第一級的分類信息示例如下:

"id" : "1-2",
"isLeaf" : null,
"isShow" : null,
"label" : "移動開發",
"name" : "移動開發",
"orderby" : 2,
"parentid" : "1"

第二級的分類是第一級分類中childrenTreeNodes屬性,它是一個數組結構:

{
"id" : "1-2",
"isLeaf" : null,
"isShow" : null,
"label" : "移動開發",
"name" : "移動開發",
"orderby" : 2,
"parentid" : "1",
"childrenTreeNodes" : [{"childrenTreeNodes" : null,"id" : "1-2-1","isLeaf" : null,"isShow" : null,"label" : "微信開發","name" : "微信開發","orderby" : 1,"parentid" : "1-2"}}

所以我們采用下面的model來定義這張表:

package com.xuecheng.content.model.dto;import com.xuecheng.content.model.po.CourseCategory;
import lombok.Data;import java.io.Serializable;
import java.util.List;/*** @description 課程分類樹型結點dto* @version 1.0*/
// Serializable 網絡傳輸序列化
@Data
public class CourseCategoryTreeDto extends CourseCategory implements Serializable {List<CourseCategoryTreeDto> childrenTreeNodes;
}

接口定義如下:

package com.xuecheng.content.api;import com.xuecheng.content.model.dto.CourseCategoryTreeDto;
import com.xuecheng.content.service.CourseCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;/*** <p>* 數據字典 前端控制器* </p>*/
@Slf4j
@RestController
public class CourseCategoryController {@GetMapping("/course-category/tree-nodes")public List<CourseCategoryTreeDto> queryTreeNodes() {return null;}
}

自鏈接查詢:?

課程分類表是一個樹型結構,其中parentid字段為父結點ID,它是樹型結構的標志字段。

如果樹的層級固定可以使用表的自鏈接去查詢,比如:我們只查詢兩級課程分類,可以用下邊的SQL:

select * from course_category oneinner join course_category two on one.id = two.parentid

我們讓?course_category 表去 inner join?自己,之后起別名,one代表一級節點分類,two代表二級節點分類,所以通過查詢 二級節點的父節點id = 一級節點id,這個就是查詢條件。

如果不想顯示根結點并且排序,參考下面代碼:?

selectone.id            one_id,one.name          one_name,one.parentid      one_parentid,one.orderby       one_orderby,one.label         one_label,two.id            two_id,two.name          two_name,two.parentid      two_parentid,two.orderby       two_orderby,two.label         two_labelfrom course_category oneinner join course_category two on one.id = two.parentidwhere one.parentid = 1and one.is_show = 1and two.is_show = 1order by one.orderby,two.orderby

而如果我們還想要通過指定節點來查詢另一張表的對應的數據,需要用到左右關聯

如上兩張圖,左側圖是課程計劃(樹型表),每個課程計劃都有所屬課程。每個課程的課程計劃有兩個級別,第一級為大章節,grade 為1、第二級為小章節,grade 為2。第二級的 parentid 為第一級的 id。課程計劃的顯示順序根據排序字段去顯示。根據業務流程中的界面原型,課程計劃列表展示時還有課程計劃關聯的視頻信息

課程計劃關聯的視頻信息在 teachplan_media 表,兩張表是一對一關系,每個課程計劃只能在teachplan_media表中存在一個視頻

我們的需求是無論關聯不關聯都必須查出課程計劃(即使沒有課程視頻也要查出課程計劃),所以選擇使用左關聯(left join)。

selectone.id             one_id,one.pname          one_pname,one.parentid       one_parentid,one.grade          one_grade,one.media_type     one_mediaType,one.start_time     one_stratTime,one.end_time       one_endTime,one.orderby        one_orderby,one.course_id      one_courseId,one.course_pub_id  one_coursePubId,two.id             two_id,two.pname          two_pname,two.parentid       two_parentid,two.grade          two_grade,two.media_type     two_mediaType,two.start_time     two_stratTime,two.end_time       two_endTime,two.orderby        two_orderby,two.course_id      two_courseId,two.course_pub_id  two_coursePubId,m1.media_fileName mediaFilename,m1.id teachplanMeidaId,m1.media_id mediaIdfrom teachplan oneINNER JOIN teachplan two on one.id = two.parentidLEFT JOIN teachplan_media m1 on m1.teachplan_id = two.idwhere one.parentid = 0 and one.course_id=#{value}order by one.orderby,two.orderby

首先使用inner join自鏈接查詢樹型表,隨后使用左關聯根據課程視頻的teachplan_id = 課程計劃的id?來找到每個課程計劃(二級分類)對應的課程視頻。?

目前我們想要的數據是如上圖,而目前查詢到的數據如下圖:

因為字段名與屬性名不一致,所以需要定義 resultMap 手動映射。而且我們想要的數據格式內還有子節點,所以需要使用一對多映射(Collection),我們的數據模型如下圖:

@Data
@ToString
public class TeachplanDto extends Teachplan {//課程計劃關聯的媒資信息TeachplanMedia teachplanMedia;//子結點List<TeachplanDto> teachPlanTreeNodes;
}

所以?property 映射的屬性就是?teachPlanTreeNodes,而 ofType 的 List 中的對象類型就是 TeachplanDto。

<!-- 一級中包含多個二級數據 -->
<collection property="teachPlanTreeNodes" ofType="com.xuecheng.content.model.dto.TeachplanDto">

而在小章節內有一個視頻,所以用到一對一映射(Assoiation),其中 property映射的就是"teachplanMedia"屬性,也就是課程視頻;而 javaType的類型就是"com.xuecheng.content.model.po.TeachplanMedia"。

<association property="teachplanMedia" javaType="com.xuecheng.content.model.po.TeachplanMedia">

下面是對應的mapper.xml文件:(通過單次 SQL 關聯查詢 + 結果集映射,一次性獲取所有層級數據,減少數據庫交互。)

<!-- 課程分類樹型結構查詢映射結果 -->
<resultMap id="treeNodeResultMap" type="com.xuecheng.content.model.dto.TeachplanDto"><!-- 一級數據映射 --><id     column="one_id"        property="id" /><result column="one_pname"      property="pname" /><result column="one_parentid"     property="parentid" /><result column="one_grade"  property="grade" /><result column="one_mediaType"   property="mediaType" /><result column="one_stratTime"   property="stratTime" /><result column="one_endTime"   property="endTime" /><result column="one_orderby"   property="orderby" /><result column="one_courseId"   property="courseId" /><result column="one_coursePubId"   property="coursePubId" /><!-- 一級中包含多個二級數據 --><collection property="teachPlanTreeNodes" ofType="com.xuecheng.content.model.dto.TeachplanDto"><!-- 二級數據映射 --><id     column="two_id"        property="id" /><result column="two_pname"      property="pname" /><result column="two_parentid"     property="parentid" /><result column="two_grade"  property="grade" /><result column="two_mediaType"   property="mediaType" /><result column="two_stratTime"   property="stratTime" /><result column="two_endTime"   property="endTime" /><result column="two_orderby"   property="orderby" /><result column="two_courseId"   property="courseId" /><result column="two_coursePubId"   property="coursePubId" /><association property="teachplanMedia" javaType="com.xuecheng.content.model.po.TeachplanMedia"><result column="teachplanMeidaId"   property="id" /><result column="mediaFilename"   property="mediaFilename" /><result column="mediaId"   property="mediaId" /><result column="two_id"   property="teachplanId" /><result column="two_courseId"   property="courseId" /><result column="two_coursePubId"   property="coursePubId" /></association></collection>
</resultMap>
<!--課程計劃樹型結構查詢-->
<select id="selectTreeNodes" resultMap="treeNodeResultMap" parameterType="long" >selectone.id             one_id,one.pname          one_pname,one.parentid       one_parentid,one.grade          one_grade,one.media_type     one_mediaType,one.start_time     one_stratTime,one.end_time       one_endTime,one.orderby        one_orderby,one.course_id      one_courseId,one.course_pub_id  one_coursePubId,two.id             two_id,two.pname          two_pname,two.parentid       two_parentid,two.grade          two_grade,two.media_type     two_mediaType,two.start_time     two_stratTime,two.end_time       two_endTime,two.orderby        two_orderby,two.course_id      two_courseId,two.course_pub_id  two_coursePubId,m1.media_fileName mediaFilename,m1.id teachplanMeidaId,m1.media_id mediaIdfrom teachplan oneINNER JOIN teachplan two on one.id = two.parentidLEFT JOIN teachplan_media m1 on m1.teachplan_id = two.idwhere one.parentid = 0 and one.course_id=#{value}order by one.orderby,two.orderby
</select>

遞歸查詢:?

如果樹的層級不確定,此時可以使用MySQL遞歸實現,使用with語法,如下:

WITH [RECURSIVE]cte_name [(col_name [, col_name] ...)] AS (subquery)[, cte_name [(col_name [, col_name] ...)] AS (subquery)] ...

cte_name :公共表達式的名稱,可以理解為表名,用來表示as后面跟著的子查詢

col_name :公共表達式包含的列名,可以寫也可以不寫

下邊是一個遞歸的簡單例子:

with RECURSIVE t1  AS
(SELECT 1 as nUNION ALLSELECT n + 1 FROM t1 WHERE n < 5
)
SELECT * FROM t1;

通過上述SQL,其中 t1 相當于一個表名,select 1 相當于這個表的初始值,這里使用UNION ALL 不斷將每次遞歸得到的數據加入到表中,而 n<5 為遞歸執行的條件,當 n>=5 時結束遞歸調用:

下邊我們使用遞歸實現課程分類的查詢:

with recursive t1 as (
select * from  course_category p where  id= '1'
union allselect t.* from course_category t inner join t1 on t1.id = t.parentid
)
select *  from t1 order by t1.id, t1.orderby

最開始根結點id=1,然后通過 union all?不斷將每次遞歸得到的數據加入到 t1 表中(t1表存儲查完的數據),隨后向下遞歸,使用 inner join 去拿 course_category 表關聯 t1?表,來查詢當前 t1 表下的樹枝,所以查詢 t1.id =?course_category.parentid,因為 parentid 中記錄的是當前結點的父節點。

所以查詢完的數據最終會保存到 t1表并且使用 order by 按照順序輸出。

查詢結果如下:

t1表中初始的數據是id等于1的記錄,即根結點。

那如何向上遞歸?

下邊的sql實現了向上遞歸:

with recursive t1 as (
select * from  course_category p where  id= '1-1-1'
union allselect t.* from course_category t inner join t1 on t1.parentid = t.id
)
select *  from t1 order by t1.id, t1.orderby

初始節點為1-1-1,通過遞歸找到它的父級節點,父級節點包括所有級別的節點。

以上是我們研究了樹型表的查詢方法,通過遞歸的方式查詢課程分類比較靈活,因為它可以不限制層級。

mysql為了避免無限遞歸默認遞歸次數為1000,可以通過設置cte_max_recursion_depth參數增加遞歸深度,還可以通過max_execution_time限制執行時間,超過此時間也會終止遞歸操作。

mysql遞歸相當于在存儲過程中執行若干次sql語句,java程序僅與數據庫建立一次鏈接執行遞歸操作,所以只要控制好遞歸深度,控制好數據量性能就沒有問題。

思考:如果java程序在遞歸操作中連接數據庫去查詢數據組裝數據,這個性能高嗎?


下邊我們可自定義mapper方法查詢課程分類,最終將查詢結果映射到List<CourseCategoryTreeDto>中。

生成課程分類表的mapper文件并拷貝至內容管理模塊 的service工程中。

public interface CourseCategoryMapper extends BaseMapper<CourseCategory> {public List<CourseCategoryTreeDto> selectTreeNodes(String id);
}

找到對應的mapper.xml文件,編寫sql語句:

<select id="selectTreeNodes" resultType="com.xuecheng.content.model.dto.CourseCategoryTreeDto" parameterType="string">with recursive t1 as (select * from  course_category p where  id= #{id}union allselect t.* from course_category t inner join t1 on t1.id = t.parentid)select *  from t1 order by t1.id, t1.orderby</select>

編寫service接口實現:

由于現在我們查詢是直接將所有的數據查出,而沒有適應接口所返回的數據格式,所以我們要在Service層處理。

所以現在分為兩步進行:

  1. 使用剛剛定義的mapper接口查詢數據
  2. 將查詢到的數據封裝成 List<CourseCategoryTreeDto> 數據格式:?
    @Data
    public class CourseCategoryTreeDto extends CourseCategory implements Serializable {List<CourseCategoryTreeDto> childrenTreeNodes;
    }
    

?下面我們講述如何將查詢到的數據封裝成 List<CourseCategoryTreeDto> 數據格式。

  1. 將list轉為map,key就是結點id,value就是CourseCategoryTreeDto對象,目的是為了方面從map獲取結點。
  2. 從頭遍歷List<CourseCategoryTreeDto>,將遍歷到的子節點放在父節點的childrenTreeNodes中。

首先List轉map可以使用stream流,并給key、value賦值,但是也會遇到兩個key重復,這個時候以第二個key為主,隨后在使用filter將根結點過濾(判斷查詢id與當前id是否相等來判斷是否為根結點,因為是通過根結點查詢)?:

//將list轉map,以備使用,排除根節點
Map<String, CourseCategoryTreeDto> mapTemp = courseCategoryTreeDtos.stream().filter(item->!id.equals(item.getId())).collect(Collectors.toMap(key -> key.getId(), value -> value, (key1, key2) -> key2));

先定義一個帶返回的List數組對象:?

List<CourseCategoryTreeDto> categoryTreeDtos = new ArrayList<>();

隨后同樣使用stream流進行處理,如果當前節點的parentid=根結點的id,那么就將其放進?List<CourseCategoryTreeDto> categoryTreeDtos ,隨后在判斷當前結點是否有父節點(通過map的get(parentid)方法找),如果沒有父節點就new一個集合放入(因為要向該集合中放入其子節點),如果要是找到其父節點,那么就將該節點放入其父節點的集合中。

下面是完整代碼:

package com.xuecheng.content.service.impl;import com.xuecheng.content.mapper.CourseCategoryMapper;
import com.xuecheng.content.model.dto.CourseCategoryTreeDto;
import com.xuecheng.content.service.CourseCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;@Slf4j
@Service
public class CourseCategoryServiceImpl implements CourseCategoryService {@AutowiredCourseCategoryMapper courseCategoryMapper;public List<CourseCategoryTreeDto> queryTreeNodes(String id) {List<CourseCategoryTreeDto> courseCategoryTreeDtos = courseCategoryMapper.selectTreeNodes(id);//將list轉map,以備使用,排除根節點Map<String, CourseCategoryTreeDto> mapTemp = courseCategoryTreeDtos.stream().filter(item->!id.equals(item.getId())).collect(Collectors.toMap(key -> key.getId(), value -> value, (key1, key2) -> key2));//最終返回的listList<CourseCategoryTreeDto> categoryTreeDtos = new ArrayList<>();//依次遍歷每個元素,排除根節點courseCategoryTreeDtos.stream().filter(item->!id.equals(item.getId())).forEach(item->{if(item.getParentid().equals(id)){categoryTreeDtos.add(item);}//找到當前節點的父節點CourseCategoryTreeDto courseCategoryTreeDto = mapTemp.get(item.getParentid());if(courseCategoryTreeDto!=null){if(courseCategoryTreeDto.getChildrenTreeNodes() ==null){courseCategoryTreeDto.setChildrenTreeNodes(new ArrayList<CourseCategoryTreeDto>());}//下邊開始往ChildrenTreeNodes屬性中放子節點courseCategoryTreeDto.getChildrenTreeNodes().add(item);}});return categoryTreeDtos;}}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/85011.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/85011.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/85011.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

微服務難題?Nacos服務發現來救場

文章目錄 前言1.什么是服務發現2.Nacos 閃亮登場2.1 服務注冊2.2 服務發現 3.Nacos 的優勢3.1 簡單易用3.2 高可用3.3 動態配置 4.實戰演練4.1安裝 Nacos4.2 服務注冊與發現示例代碼&#xff08;以 Spring Boot 為例&#xff09; 總結 前言 大家好&#xff0c;我是沛哥兒。今天…

AStar低代碼平臺-腳本調用C#方法

修改報工表表單&#xff0c;右鍵定義彈出菜單&#xff0c;新增一個菜單項&#xff0c;并在點擊事件腳本中編寫調用腳本。 編譯腳本&#xff0c;然后在模塊代碼里面定義這個方法&#xff1a; public async Task<int> on_call_import(DataRow curRow) {PrintDataRow(cur…

python調用langchain實現RAG

一、安裝langchain 安裝依賴 python -m venv env.\env\Scripts\activatepip3 install langchainpip3 install langchain-corepip3 install langchain-openaipip3 install langchain-communitypip3 install dashscopepip3 install langchain_postgrespip3 install "psyc…

大學大模型教學:基于NC數據的全球氣象可視化解決方案

引言 氣象數據通常以NetCDF(Network Common Data Form)格式存儲,這是一種廣泛應用于科學數據存儲的二進制文件格式。在大學氣象學及相關專業的教學中,掌握如何讀取、處理和可視化NC數據是一項重要技能。本文將詳細介紹基于Python的NC數據處理與可視化解決方案,包含完整的代…

ORB-SLAM2學習筆記:ComputeKeyPointsOctTree分析過程記錄

ComputeKeyPointsOctTree是ORB特征提取器中計算關鍵點的部分&#xff0c;特別是使用八叉樹&#xff08;OctTree&#xff09;方法進行關鍵點分布。 首先&#xff0c;函數參數是vector<vector的引用allKeypoints&#xff0c;用來存儲各層的關鍵點。代碼開頭調整了allKeypoint…

LeetCode Hot100(多維動態規劃)

62. 不同路徑 比較板子的dp&#xff0c;實際上就是到達一個點有兩種方式&#xff0c;從上面來或者是左邊&#xff0c;加起來就可以了 class Solution {public int uniquePaths(int m, int n) {int [][]arr new int[m2][n2];arr[1][1]1;for(int i1;i<m;i){for(int j1;j<…

Oracle MOVE ONLINE 實現原理

Oracle MOVE ONLINE 實現原理 Oracle 的 MOVE ONLINE 操作是一種在線重組表的技術&#xff0c;允許在不中斷業務的情況下重新組織表數據。以下是其實現原理的詳細分析&#xff1a; 基本概念 MOVE ONLINE 是 Oracle 12c 引入的特性&#xff0c;用于替代傳統的 ALTER TABLE ..…

工作流長任務處置方案

以下是前后端協作處理長任務工作流的完整實現方案&#xff0c;結合技術選型與設計要點&#xff0c;以清晰結構呈現&#xff1a; 一、后端實現方案 異步任務隊列架構 ? 技術選型&#xff1a; ? 消息隊列&#xff1a;NATS&#xff08;輕量級&#xff09;或 RabbitMQ&#xf…

RabbitMQ仲裁隊列高可用架構解析

#作者&#xff1a;閆乾苓 文章目錄 概述工作原理1.節點之間的交互2.消息復制3.共識機制4.選舉領導者5.消息持久化6.自動故障轉移 集群環境節點管理仲裁隊列增加集群節點重新平衡仲裁隊列leader所在節點仲裁隊列減少集群節點 副本管理add_member 在給定節點上添加仲裁隊列成員&…

fingerprint2瀏覽器指紋使用記錄

我在uniapp-vue3-H5端使用的&#xff0c;記錄一下 抄的這里前端使用fingerprintjs2獲取瀏覽器指紋fingerprintjs2是通過設備瀏覽器信息獲取瀏覽器指紋的插件&#xff08; - 掘金 1、安裝依賴 npm i fingerprintjs2 -S2、抽成模塊文件&#xff0c;/utils/Fingerprint2.js 生成指…

深度學習面試八股簡略速覽

在準備深度學習面試時&#xff0c;你可能會感到有些不知所措。畢竟&#xff0c;深度學習是一個龐大且不斷發展的領域&#xff0c;涉及眾多復雜的技術和概念。但別擔心&#xff0c;本文將為你提供一份全面的指南&#xff0c;從基礎理論到實際應用&#xff0c;幫助你在面試中脫穎…

使用 Redis 作為向量數據庫

一、什么是向量數據庫&#xff1f; 向量&#xff08;Vector&#xff09;&#xff1a;在機器學習和 AI 中&#xff0c;向量是由一系列數字組成的序列&#xff0c;用于數值化地描述數據的特征或語義。文本、圖像、音頻等非結構化數據可以通過模型轉換成固定長度的向量。 向量數據…

變量的計算

不同類型變量之間的計算 數字型變量可以直接計算 在python中&#xff0c;數字型變量可以直接通過算術運算符計算bool型變量&#xff1a;True 對應數字1 &#xff1b;False 對應數字0、 字符串變量 使用 拼接字符串 使用 * 拼接指定倍數的相同字符串 變量的輸入&#xff1a;&…

PostgreSQL學會如何建表

開始使用PostgreSQL之前&#xff0c; 上一節我們說了怎樣安裝它。 PostgreSQL可能已經安裝到你的電腦上了,安裝后postgre服務默認在電腦開機時運行啟動。 一.了解PostgreSQL的運行 PostgreSQL使用一種客戶端/服務器&#xff08;C/S&#xff09;模型。 和其他典型的客戶端/服務…

Linux驅動學習筆記(十)

熱插拔 1.熱插拔&#xff1a;就是帶電插拔&#xff0c;即允許用戶在不關閉系統&#xff0c;不切斷電源的情況下拆卸或安裝硬盤&#xff0c;板卡等設備。熱插拔是內核和用戶空間之間&#xff0c;通過調用用戶空間程序實現交互來實現的&#xff0c;當內核發生了某種熱拔插事件時…

大模型應用開發第五講:成熟度模型:從ChatGPT(L2)到未來自主Agent(L4)

大模型應用開發第五講&#xff1a;成熟度模型&#xff1a;從ChatGPT&#xff08;L2&#xff09;到未來自主Agent&#xff08;L4&#xff09; 資料取自《大模型應用開發&#xff1a;動手做AI Agent 》。 查看總目錄&#xff1a;學習大綱 關于DeepSeek本地部署指南可以看下我之…

Delphi 導入excel

Delphi導入Excel的常見方法可分為兩種主流方案&#xff1a;基于OLE自動化操作Excel原生接口和利用第三方組件庫。以下為具體實現流程及注意事項&#xff1a; ?一、OLE自動化方案&#xff08;推薦基礎場景&#xff09;? 該方法通過COM接口調用本地安裝的Excel程序&#xff0c…

Selenium的第四天打卡——Selenium瀏覽器應用(完整版)

Selenium瀏覽器應用 目錄 Selenium瀏覽器應用 一、瀏覽器操作示例代碼 1.設置瀏覽器縮放大小 2.瀏覽器前進和后退 3.瀏覽器刷新 二、WebDriver常見方法 三、鼠標事件示例 四、鍵盤事件示例 五、獲取斷言信息 六、窗口的切換 七、關鍵注意事項 一、瀏覽器操作示例代…

PMO價值重構:從項目管理“交付機器”到“戰略推手”

在數字化轉型浪潮中&#xff0c;項目管理辦公室&#xff08;PMO&#xff09;正經歷著前所未有的角色蛻變。傳統上&#xff0c;PMO往往被視為項目管理的“交付機器”&#xff0c;專注于項目的按時交付和資源分配。然而&#xff0c;隨著企業對戰略執行的重視&#xff0c;PMO正逐漸…

本地依賴庫的版本和庫依賴的版本不一致如何解決?

我用的 yarn v4 版本&#xff0c;所以以下教程命令都基于yarn 這里假設我報錯的庫名字叫 XXXXXXXX&#xff0c;依賴他的庫叫 AAAAAAAA 排查解決思路分析&#xff1a; 首先查看一下 XXXXXXXX 的依賴關系&#xff0c;執行 yarn why XXXXXXXX 首先我們要知道 yarn 自動做了庫…