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

Java程序递归及mybatis递归查询

之前项目组有个需求,定时同步机构的信息。已知三方接口由于返回数据量很大,所以最后需要三方提供一个可根据机构编号获取当前机构及子机构信息的接口。而不是一次性返回全部机构信息!

由于这次需求也用到了递归,所以记录下!

Java程序递归查询

pom.xml文件

<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.73</version>
</dependency>

数据库 

organization机构表

表结构sql

DROP TABLE IF EXISTS `organization`;
CREATE TABLE `organization`  (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',`org_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '机构编号',`org_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '机构名称',`parent_id` int(20) NULL DEFAULT NULL COMMENT '父级机构id',`parent_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '父级机构编码',`parent_all_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT '所有父级code',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 50 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic;

organization_record 机构记录表

将机构表数据及原始三方接口数据以子节点形式存储到记录表中

CREATE TABLE `organization_record`  (`id` int(4) NOT NULL AUTO_INCREMENT COMMENT '主键',`organization_info` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '机构数据的json串存储',`organization_source_info` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '原始机构数据的json串存储',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 18 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

机构实体类 Organization

package com.example.demo.entity;import lombok.Data;
import java.io.Serializable;
import java.util.List;@Data
public class Organization  implements Serializable {private   int id;//机构编号private  String orgCode;//机构名称private  String orgName;//父级idprivate  int parentId;//父级机构编号private  String parentCode;//所有父级codeprivate  String parentAllCode;private List<Organization> children;
}

mapper

机构mapper

package com.example.demo.mapper;import com.example.demo.entity.Organization;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;@Mapper
public interface OrganizationMapper {//添加组织机构int insertOrganization(Organization organization);//根据组织编号查询信息Organization queryOrganizationByCode(String code);//修改组织机构信息int updateOrganization(Organization organization);//根据code查询对应的组织机构List<Organization> queryOrganizationByParentId(@Param("parentId") String parentId);
}

 机构记录mapper

package com.example.demo.mapper;import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;@Mapper
public interface OrganizationRecordMapper {//添加void  insertOrganizationRecord(@Param("organizationInfo") String organizationInfo,@Param("organizationSourceInfo") String organizationSourceInfo);}

SQL

机构sql

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.OrganizationMapper"><resultMap id="organizationMap" type="com.example.demo.entity.Organization"><result property="id" column="id"/><result property="orgCode" column="org_code"/><result property="orgName" column="org_name"/><result property="parentId" column="parent_id"/><result property="parentCode" column="parent_code"/><result property="parentAllCode" column="parent_all_code"/></resultMap><!--新增--><insert id="insertOrganization" parameterType="com.example.demo.entity.Organization">INSERT INTO organization (org_code,org_name,parent_id,parent_code,parent_all_code)VALUE (#{orgCode},#{orgName},#{parentId},#{parentCode},#{parentAllCode})</insert><!--根据code查询对应的组织机构--><select id="queryOrganizationByParentId" resultMap="organizationMap">select * from organization<where><if test="parentId!='-1'">and  parent_id=#{parentId}</if></where></select><!--根据组织编号查询机构信息--><select id="queryOrganizationByCode" parameterType="string" resultMap="organizationMap">select * from organization where org_code=#{code} limit 0,1</select><!--修改--><update id="updateOrganization" parameterType="com.example.demo.entity.Organization">UPDATE organizationSET org_name = #{orgName},parent_id = #{parentId},parent_code = #{parentCode},parent_all_code = #{parentAllCode}WHERE org_code = #{orgCode}</update>
</mapper>

机构记录sql

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.OrganizationRecordMapper"><!--添加--><insert id="insertOrganizationRecord" >insert into organization_record(organization_info,organization_source_info)VALUES(#{organizationInfo},#{organizationSourceInfo})</insert>
</mapper>

 业务逻辑service

package com.example.demo.service;import com.alibaba.fastjson.JSONArray;
import com.example.demo.entity.Organization;
import com.example.demo.mapper.OrganizationMapper;
import com.example.demo.mapper.OrganizationRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;@Slf4j
@Service
public class TestDiGuiService {@Autowiredprivate OrganizationMapper organizationMapper;@Autowiredprivate OrganizationRecordMapper organizationRecordMapper;public HashMap<String, Object> syncOrganization() {HashMap<String, Object> resultMap = new HashMap<>();List<HashMap<String, Object>> sourceList = new ArrayList<>();  //原始机构信息集合//1.模拟请求三方接口获取信息 TODOMap emp = new HashMap();List<HashMap<String, Object>> mapList = new ArrayList<>();HashMap<String, Object> hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0001");hashMap.put("ORG_NAME", "中国工商银行");mapList.add(hashMap);hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0002");hashMap.put("ORG_NAME", "北京银行");mapList.add(hashMap);emp.put("result", mapList);emp.put("status", "200");String code = (String) emp.get("status");if (!"200".equals(code)) {resultMap.put("code", "500");return resultMap;}List<HashMap<String, Object>> list = (List<HashMap<String, Object>>) emp.get("result");sourceList.addAll(list);//2.对数据进行逻辑处理if (list.size() != 0) {for (HashMap<String, Object> object : list) {//2.1 对信息封装为组织机构代码对象Organization organization = conversionOrg("0", object);//2.2 新增/修改机构信息disposeOrg(organization);//2.3 递归遍历recursive(organization, sourceList);}}resultMap.put("code", "200");//3.查询出全部机构信息,整理为json串queryOrganization(sourceList);return resultMap;}//封装成对象public Organization conversionOrg(String orgCode, HashMap<String, Object> map) {Organization o = new Organization();String code = (String) map.get("ORG_CODE");String name = (String) map.get("ORG_NAME");log.info("组织机构名称={},机构编号={}", name, code);o.setOrgCode(code);o.setOrgName(name);Organization organization = organizationMapper.queryOrganizationByCode(orgCode);if (organization == null) {o.setParentAllCode("0,");} else {String parentAllCode = StringUtils.isEmpty(organization.getParentAllCode()) ? "0," : organization.getParentAllCode() + orgCode + ",";o.setParentAllCode(parentAllCode);o.setParentId(organization.getId());o.setParentCode(organization.getOrgCode());}return o;}//逻辑处理 机构若存在该机构代码,则进行修改;否则进行新增public void disposeOrg(Organization organization) {Organization org = organizationMapper.queryOrganizationByCode(organization.getOrgCode());if (org == null || "".equals(org.getOrgCode()) || !organization.getOrgCode().equals(org.getOrgCode())) {organizationMapper.insertOrganization(organization);log.info("新增完成!机构编号={},组织机构名称={}", organization.getOrgCode(), organization.getOrgName());} else {organizationMapper.updateOrganization(organization);log.info("修改完成!机构编号={},组织机构名称={}", organization.getOrgCode(), organization.getOrgName());}}//递归遍历机构下面的子机构信息public void recursive(Organization organization, List<HashMap<String, Object>> sourceList) {try {Thread.currentThread().sleep(2000);} catch (Exception e) {e.printStackTrace();}//模拟请求三方接口中二级机构及其子机构的信息 TODOMap emp = new HashMap();List<HashMap<String, Object>> mapList = new ArrayList<>();HashMap<String, Object> hashMap = new HashMap<>();if ("0001".equals(organization.getOrgCode())) {hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0011");hashMap.put("ORG_NAME", "丰台区");mapList.add(hashMap);hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0021");hashMap.put("ORG_NAME", "海淀区");mapList.add(hashMap);}if ("0002".equals(organization.getOrgCode())) {hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0012");hashMap.put("ORG_NAME", "丰台区");mapList.add(hashMap);hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0022");hashMap.put("ORG_NAME", "大兴区");mapList.add(hashMap);}if ("0011".equals(organization.getOrgCode())) {hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0031");hashMap.put("ORG_NAME", "马家堡");mapList.add(hashMap);hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0041");hashMap.put("ORG_NAME", "角门西");mapList.add(hashMap);}if ("0021".equals(organization.getOrgCode())) {hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0051");hashMap.put("ORG_NAME", "白堆子");mapList.add(hashMap);}if ("0012".equals(organization.getOrgCode())) {hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0032");hashMap.put("ORG_NAME", "岳各庄");mapList.add(hashMap);hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0042");hashMap.put("ORG_NAME", "大红门");mapList.add(hashMap);}if ("0022".equals(organization.getOrgCode())) {hashMap = new HashMap<>();hashMap.put("ORG_CODE", "0052");hashMap.put("ORG_NAME", "圆明园");mapList.add(hashMap);}emp.put("result", mapList);emp.put("status", "200");String code = (String) emp.get("status");if (!"200".equals(code)) {return;}List<HashMap<String, Object>> list = (List<HashMap<String, Object>>) emp.get("result");sourceList.addAll(list);if (list.size() != 0) {for (HashMap<String, Object> object : list) {Organization conversionOrg = conversionOrg(organization.getOrgCode(), object);disposeOrg(conversionOrg);recursive(conversionOrg, sourceList);}}}public List<Organization> queryOrganization(List<HashMap<String, Object>> sourceList) {List<Organization> organizationList = organizationMapper.queryOrganizationByParentId("-1");List<Organization> parentList = organizationList.stream().filter(item -> item.getParentId() == 0).collect(Collectors.toList());for (Organization organization : parentList) {List<Organization> children = getChildren(organization, organizationList);organization.setChildren(children);}String json = JSONArray.toJSONString(parentList);String sourceJson = JSONArray.toJSONString(sourceList);organizationRecordMapper.insertOrganizationRecord(json,sourceJson);return parentList;}//获取当前节点的所有子节点public List<Organization> getChildren(Organization organization, List<Organization> organizationList) {List<Organization> list = organizationList.stream().filter(item -> item.getParentId() == organization.getId()).collect(Collectors.toList());if (CollectionUtils.isEmpty(list)) {return null;}for (Organization org : list) {org.setChildren(getChildren(org, organizationList));}return list;}
}

controller类

package com.example.demo.controller;import com.example.demo.service.TestDiGuiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;@RestController
@RequestMapping("/digui")
public class DiGuiController {@AutowiredTestDiGuiService testDiGuiService;@RequestMapping("syncOrg")public HashMap<String, Object> synchronousOrganization() {return testDiGuiService.syncOrganization();}
}

请求结果

postman调用接口

机构表 

 机构记录表

mybatis递归查询

也可通过mybatis查询属性结构信息,一般数据量少的可以通过SQL实现

OrganizationMapper文件

package com.example.demo.mapper;import com.example.demo.entity.Organization;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;/*** 组织机构mapper*/
@Mapper
public interface OrganizationMapper {//查询全部数据List<Organization> queryAll(@Param("code") String code);
}

SQL

<collection property="children" column="org_code" select="getChildrenTreeByParentCode"/>的column设置的是父节点SQL的返回结果的列名。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.OrganizationMapper"><resultMap id="orgResultMap" type="com.example.demo.entity.Organization"><id property="id" column="id"/><result property="orgCode" column="org_code"/><result property="orgName" column="org_name"/><result property="parentCode" column="parent_code"/><result property="parentId" column="parent_id"/><result property="parentAllCode" column="parent_all_code"/><collection property="children" column="org_code" select="getChildrenTreeByParentCode"></collection></resultMap><!--级联查询父节点--><select id="queryAll" resultMap="orgResultMap" parameterType="String">select *from organizationwhere parent_code=#{code}</select><!--级联查询子节点--><select id="getChildrenTreeByParentCode" resultMap="orgResultMap">select *from organizationwhere parent_code=#{org_code}</select>
</mapper>

controller

package com.example.demo.controller;import com.example.demo.entity.Organization;
import com.example.demo.mapper.OrganizationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;@RestController
@RequestMapping("/digui")
public class DiGuiController {@AutowiredOrganizationMapper organizationMapper;@RequestMapping("test")public List<Organization> test(@RequestParam("code")String code) {List<Organization> organizationList = organizationMapper.queryAll(code);return organizationList;}
}

调用结果

可看出执行顺序:先执行父节点SQL,后根据每条返回的结果SQL的org_code列作为入参递归查询子节点SQL。

递归能力欠缺,请各位大佬提出意见及错误!

相关文章:

Java程序递归及mybatis递归查询

之前项目组有个需求&#xff0c;定时同步机构的信息。已知三方接口由于返回数据量很大&#xff0c;所以最后需要三方提供一个可根据机构编号获取当前机构及子机构信息的接口。而不是一次性返回全部机构信息&#xff01; 由于这次需求也用到了递归&#xff0c;所以记录下&#…...

苹果电脑安装双系统步骤 教你苹果电脑如何装双系统

许多人刚买来苹果电脑时&#xff0c;对苹果的IOS操作系统比较陌生&#xff0c;显得非常不适应&#xff0c;都会去想吧苹果电脑去安装一个自己熟悉的Windows系统&#xff0c;方便自己办公娱乐&#xff0c;那么苹果电脑安装双系统的步骤怎么样呢 小编给大家介绍下吧。 许多人刚买…...

Axios-入门

介绍 Axios对原生Ajax进行了封装&#xff0c;简化书写&#xff0c;快速开发 官网&#xff1a;Axios中文文档 | Axios中文网 (axios-http.cn) 入门 1引入Axios的js文件 <script src"js/axios.js"></script> 2使用Axios发送请求&#xff0c;并获取响应…...

Python22 Pandas库

Pandas 是一个Python数据分析库&#xff0c;它提供了高性能、易于使用的数据结构和数据分析工具。这个库适用于处理和分析输入数据&#xff0c;常见于统计分析、金融分析、社会科学研究等领域。 1.Pandas的核心功能 Pandas 库的核心功能包括&#xff1a; 1.数据结构&#xff…...

不同表格式下的小文件治理方式(开源RC file/ORC/Text非事务表、事务表、Holodesk表格式..)

友情链接&#xff1a; 小文件治理系列之为什么会出现小文件问题&#xff0c;小文件过多问题的危害以及不同阶段下的小文件治理最佳解决手段 小文件过多的解决方法&#xff08;不同阶段下的治理手段&#xff0c;SQL端、存储端以及计算端&#xff09; 概览 在前两篇博文中&am…...

0.7 模拟电视标准 PAL 简介

0.7 模拟电视标准PAL PAL 是一种用于模拟电视的彩色编码系统&#xff0c;全名为逐行倒相&#xff08;Phase Alternating Line&#xff09;。它是三大模拟彩色电视标准之一&#xff0c;另外两个标准是 NTSC 和 SECAM。“逐行倒相”的意思是每行扫描线的彩色信号会跟上一行倒相&…...

vue项目中封装element分页组件

我们都知道封装组件是为了方便在项目中使用&#xff0c;全局封装之后哪个模块使用直接复制就行了&#xff0c;分页在后台项目中用到的地方也是很多的&#xff0c;所以我们就全局封装一下分页组件&#xff0c;以后也方便在项目中使用&#xff0c;接下来封装的这个分页也是elemen…...

linux下docker安装与镜像容器管理

linux下docker安装与镜像容器管理 原文链接&#xff1a;linux下docker安装与镜像容器管理 导言 ubuntu22.04-docker engine安装&#xff0c;以及镜像容器管理 docker非常简单介绍 docker就是一个虚拟化容器&#xff0c;image是镜像&#xff0c;就是一个dockerfile指明这个镜…...

【Unity】RPG2D龙城纷争(六)关卡编辑器之角色编辑

更新日期:2024年6月26日。 项目源码:第五章发布(正式开始游戏逻辑的章节) 索引 简介一、角色编辑模式1.将字段限制为只读2.创建角色(刷角色)3.预览所有角色4.编辑选中角色属性5.移动角色位置6.移除角色简介 上一篇完成的关卡编辑器已支持创建关卡环境(主要由地块单元组…...

【鸿蒙】鸿蒙的Stage和 FA 有什么区别

鸿蒙的Stage模型和FA&#xff08;Feature Ability&#xff09;模型在多个方面存在显著的区别。以下是它们之间的主要差异点&#xff1a; 设计思想和出发点&#xff1a; Stage模型&#xff1a;设计基于为复杂应用而开发的出发点&#xff0c;旨在提供一个更好的开发方式&#xff…...

JAVA小知识29:IO流(上)

IO流是指在计算机中进行输入和输出操作的一种方式&#xff0c;用于读取和写入数据。IO流主要用于处理数据传输&#xff0c;可以将数据从一个地方传送到另一个地方&#xff0c;例如从内存到硬盘&#xff0c;从网络到内存等。IO流在编程中非常常见&#xff0c;特别是在文件操作和…...

大学生毕业季,寄物流快递避雷指南

随着毕业季的来临&#xff0c;大学生们纷纷开始整理自己的行李&#xff0c;准备离开校园&#xff0c;踏入社会。 在这个过程中&#xff0c;寄送快递成为了一个不可或缺的环节。然而&#xff0c;在寄送快递的过程中&#xff0c;如果不注意一些细节&#xff0c;很容易遭遇各种“…...

如何提高项目风险的处理效率?5个重点

提高项目风险的处理效率&#xff0c;有助于迅速识别和应对风险&#xff0c;减少风险导致的延误&#xff0c;降低成本&#xff0c;提升项目质量&#xff0c;确保项目按时交付。如果项目风险处理效率较低&#xff0c;未能及时发现和处理风险&#xff0c;导致问题累积&#xff0c;…...

ZNB40 矢量网络分析仪

ZNB40 矢量网络分析仪 100kHz至40GHz的宽频率范围&#xff0c;具有四个端口和附加信号发生器 概述 R&SZNB40 提供 100 kHz 至 40 GHz 的宽频率范围&#xff0c;具有四个端口和附加信号发生器。 罗德与施瓦茨带四个端口和附加内部信号源的 40 GHz 中档矢量网络分析仪&…...

ingress代理前后端服务跨域

一、前言 ingress对于前后端服务的代理有不同的方式可以实现&#xff0c;前后端服务可以通过不同的域名实现流量的分流策略&#xff0c;不过这需要解决前后端域名不同产生的跨域问题&#xff0c;也可以通过不同的path实现流量的分流策略&#xff0c;该方式不会产生跨域的问题 …...

Python 使用 Thick 方式连接 Oracle Database BaseDB 23ai

Python 使用 Thick 方式连接 Oracle Database BaseDB 23ai 1. 下载Basic.zip 和SQL*Plus&#xff08;.zip&#xff09;2. 配置环境变量3. 连接 23ai 1. 下载Basic.zip 和SQL*Plus&#xff08;.zip&#xff09; 到 https://www.oracle.com/database/technologies/instant-clien…...

Java操作Redis(通过Jedis)

一、环境搭建 这里我使用的SpringBoot版本是2.6.3&#xff0c;所以我引入的Jedis相关版本也不是很高 <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>3.2.0</version></dependency><…...

JVM专题二:Java如何进行编译的

编程语言分类 通常我们将编程语言分为高级语言和低级语言&#xff0c;通常高级语言因为其易用性和可移植性而被广泛使用&#xff0c;而低级语言在需要对硬件进行精细控制时非常有用&#xff0c;例如在嵌入式系统编程或操作系统开发中。 高级语言更接近人类语言&#xff0c;易于…...

道路元素位置和方向的坐标系统: 点 线 面 连接点

道路元素位置和方向的坐标系统: 下图道路元素在地球坐标系中的位置&#xff0c;该位置由三个坐标轴&#xff08;x, y, z&#xff09;组成的笛卡尔坐标系来确定。这种描述特别适用于三维建模和地理信息系统&#xff08;GIS&#xff09;中&#xff0c;其中道路被视为一个三维模型…...

二、Docker常用命令

一、帮助启动类命令 1、启动docker [rootlocalhost ~]# systemctl start docker 2、停止docker [rootlocalhost ~]# systemctl stop docker 3、重启docker [rootlocalhost ~]# systemctl stop docker 4、查看docker状态 [rootlocalhost ~]# systemctl status docker 5、开机自…...

FFmpeg 低延迟同屏方案

引言 在实时互动需求激增的当下&#xff0c;无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作&#xff0c;还是游戏直播的画面实时传输&#xff0c;低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架&#xff0c;凭借其灵活的编解码、数据…...

如何在看板中体现优先级变化

在看板中有效体现优先级变化的关键措施包括&#xff1a;采用颜色或标签标识优先级、设置任务排序规则、使用独立的优先级列或泳道、结合自动化规则同步优先级变化、建立定期的优先级审查流程。其中&#xff0c;设置任务排序规则尤其重要&#xff0c;因为它让看板视觉上直观地体…...

【算法训练营Day07】字符串part1

文章目录 反转字符串反转字符串II替换数字 反转字符串 题目链接&#xff1a;344. 反转字符串 双指针法&#xff0c;两个指针的元素直接调转即可 class Solution {public void reverseString(char[] s) {int head 0;int end s.length - 1;while(head < end) {char temp …...

Psychopy音频的使用

Psychopy音频的使用 本文主要解决以下问题&#xff1a; 指定音频引擎与设备&#xff1b;播放音频文件 本文所使用的环境&#xff1a; Python3.10 numpy2.2.6 psychopy2025.1.1 psychtoolbox3.0.19.14 一、音频配置 Psychopy文档链接为Sound - for audio playback — Psy…...

Web 架构之 CDN 加速原理与落地实践

文章目录 一、思维导图二、正文内容&#xff08;一&#xff09;CDN 基础概念1. 定义2. 组成部分 &#xff08;二&#xff09;CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 &#xff08;三&#xff09;CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 &#xf…...

回溯算法学习

一、电话号码的字母组合 import java.util.ArrayList; import java.util.List;import javax.management.loading.PrivateClassLoader;public class letterCombinations {private static final String[] KEYPAD {"", //0"", //1"abc", //2"…...

代码随想录刷题day30

1、零钱兑换II 给你一个整数数组 coins 表示不同面额的硬币&#xff0c;另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额&#xff0c;返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带…...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...

基于Java+VUE+MariaDB实现(Web)仿小米商城

仿小米商城 环境安装 nodejs maven JDK11 运行 mvn clean install -DskipTestscd adminmvn spring-boot:runcd ../webmvn spring-boot:runcd ../xiaomi-store-admin-vuenpm installnpm run servecd ../xiaomi-store-vuenpm installnpm run serve 注意&#xff1a;运行前…...

全面解析数据库:从基础概念到前沿应用​

在数字化时代&#xff0c;数据已成为企业和社会发展的核心资产&#xff0c;而数据库作为存储、管理和处理数据的关键工具&#xff0c;在各个领域发挥着举足轻重的作用。从电商平台的商品信息管理&#xff0c;到社交网络的用户数据存储&#xff0c;再到金融行业的交易记录处理&a…...