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

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

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

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

不同表格式下的小文件治理方式(开源RC file/ORC/Text非事务表、事务表、Holodesk表格式..)
友情链接: 小文件治理系列之为什么会出现小文件问题,小文件过多问题的危害以及不同阶段下的小文件治理最佳解决手段 小文件过多的解决方法(不同阶段下的治理手段,SQL端、存储端以及计算端) 概览 在前两篇博文中&am…...

0.7 模拟电视标准 PAL 简介
0.7 模拟电视标准PAL PAL 是一种用于模拟电视的彩色编码系统,全名为逐行倒相(Phase Alternating Line)。它是三大模拟彩色电视标准之一,另外两个标准是 NTSC 和 SECAM。“逐行倒相”的意思是每行扫描线的彩色信号会跟上一行倒相&…...
vue项目中封装element分页组件
我们都知道封装组件是为了方便在项目中使用,全局封装之后哪个模块使用直接复制就行了,分页在后台项目中用到的地方也是很多的,所以我们就全局封装一下分页组件,以后也方便在项目中使用,接下来封装的这个分页也是elemen…...
linux下docker安装与镜像容器管理
linux下docker安装与镜像容器管理 原文链接:linux下docker安装与镜像容器管理 导言 ubuntu22.04-docker engine安装,以及镜像容器管理 docker非常简单介绍 docker就是一个虚拟化容器,image是镜像,就是一个dockerfile指明这个镜…...
【Unity】RPG2D龙城纷争(六)关卡编辑器之角色编辑
更新日期:2024年6月26日。 项目源码:第五章发布(正式开始游戏逻辑的章节) 索引 简介一、角色编辑模式1.将字段限制为只读2.创建角色(刷角色)3.预览所有角色4.编辑选中角色属性5.移动角色位置6.移除角色简介 上一篇完成的关卡编辑器已支持创建关卡环境(主要由地块单元组…...
【鸿蒙】鸿蒙的Stage和 FA 有什么区别
鸿蒙的Stage模型和FA(Feature Ability)模型在多个方面存在显著的区别。以下是它们之间的主要差异点: 设计思想和出发点: Stage模型:设计基于为复杂应用而开发的出发点,旨在提供一个更好的开发方式ÿ…...

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

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

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

ZNB40 矢量网络分析仪
ZNB40 矢量网络分析仪 100kHz至40GHz的宽频率范围,具有四个端口和附加信号发生器 概述 R&SZNB40 提供 100 kHz 至 40 GHz 的宽频率范围,具有四个端口和附加信号发生器。 罗德与施瓦茨带四个端口和附加内部信号源的 40 GHz 中档矢量网络分析仪&…...
ingress代理前后端服务跨域
一、前言 ingress对于前后端服务的代理有不同的方式可以实现,前后端服务可以通过不同的域名实现流量的分流策略,不过这需要解决前后端域名不同产生的跨域问题,也可以通过不同的path实现流量的分流策略,该方式不会产生跨域的问题 …...
Python 使用 Thick 方式连接 Oracle Database BaseDB 23ai
Python 使用 Thick 方式连接 Oracle Database BaseDB 23ai 1. 下载Basic.zip 和SQL*Plus(.zip)2. 配置环境变量3. 连接 23ai 1. 下载Basic.zip 和SQL*Plus(.zip) 到 https://www.oracle.com/database/technologies/instant-clien…...
Java操作Redis(通过Jedis)
一、环境搭建 这里我使用的SpringBoot版本是2.6.3,所以我引入的Jedis相关版本也不是很高 <dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>3.2.0</version></dependency><…...
JVM专题二:Java如何进行编译的
编程语言分类 通常我们将编程语言分为高级语言和低级语言,通常高级语言因为其易用性和可移植性而被广泛使用,而低级语言在需要对硬件进行精细控制时非常有用,例如在嵌入式系统编程或操作系统开发中。 高级语言更接近人类语言,易于…...

道路元素位置和方向的坐标系统: 点 线 面 连接点
道路元素位置和方向的坐标系统: 下图道路元素在地球坐标系中的位置,该位置由三个坐标轴(x, y, z)组成的笛卡尔坐标系来确定。这种描述特别适用于三维建模和地理信息系统(GIS)中,其中道路被视为一个三维模型…...
二、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、开机自…...
基于算法竞赛的c++编程(28)结构体的进阶应用
结构体的嵌套与复杂数据组织 在C中,结构体可以嵌套使用,形成更复杂的数据结构。例如,可以通过嵌套结构体描述多层级数据关系: struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...
FastAPI 教程:从入门到实践
FastAPI 是一个现代、快速(高性能)的 Web 框架,用于构建 API,支持 Python 3.6。它基于标准 Python 类型提示,易于学习且功能强大。以下是一个完整的 FastAPI 入门教程,涵盖从环境搭建到创建并运行一个简单的…...

蓝牙 BLE 扫描面试题大全(2):进阶面试题与实战演练
前文覆盖了 BLE 扫描的基础概念与经典问题蓝牙 BLE 扫描面试题大全(1):从基础到实战的深度解析-CSDN博客,但实际面试中,企业更关注候选人对复杂场景的应对能力(如多设备并发扫描、低功耗与高发现率的平衡)和前沿技术的…...
vue3 字体颜色设置的多种方式
在Vue 3中设置字体颜色可以通过多种方式实现,这取决于你是想在组件内部直接设置,还是在CSS/SCSS/LESS等样式文件中定义。以下是几种常见的方法: 1. 内联样式 你可以直接在模板中使用style绑定来设置字体颜色。 <template><div :s…...
【Java学习笔记】BigInteger 和 BigDecimal 类
BigInteger 和 BigDecimal 类 二者共有的常见方法 方法功能add加subtract减multiply乘divide除 注意点:传参类型必须是类对象 一、BigInteger 1. 作用:适合保存比较大的整型数 2. 使用说明 创建BigInteger对象 传入字符串 3. 代码示例 import j…...

Selenium常用函数介绍
目录 一,元素定位 1.1 cssSeector 1.2 xpath 二,操作测试对象 三,窗口 3.1 案例 3.2 窗口切换 3.3 窗口大小 3.4 屏幕截图 3.5 关闭窗口 四,弹窗 五,等待 六,导航 七,文件上传 …...
C++课设:简易日历程序(支持传统节假日 + 二十四节气 + 个人纪念日管理)
名人说:路漫漫其修远兮,吾将上下而求索。—— 屈原《离骚》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 专栏介绍:《编程项目实战》 目录 一、为什么要开发一个日历程序?1. 深入理解时间算法2. 练习面向对象设计3. 学习数据结构应用二、核心算法深度解析…...
【LeetCode】3309. 连接二进制表示可形成的最大数值(递归|回溯|位运算)
LeetCode 3309. 连接二进制表示可形成的最大数值(中等) 题目描述解题思路Java代码 题目描述 题目链接:LeetCode 3309. 连接二进制表示可形成的最大数值(中等) 给你一个长度为 3 的整数数组 nums。 现以某种顺序 连接…...
关于uniapp展示PDF的解决方案
在 UniApp 的 H5 环境中使用 pdf-vue3 组件可以实现完整的 PDF 预览功能。以下是详细实现步骤和注意事项: 一、安装依赖 安装 pdf-vue3 和 PDF.js 核心库: npm install pdf-vue3 pdfjs-dist二、基本使用示例 <template><view class"con…...
libfmt: 现代C++的格式化工具库介绍与酷炫功能
libfmt: 现代C的格式化工具库介绍与酷炫功能 libfmt 是一个开源的C格式化库,提供了高效、安全的文本格式化功能,是C20中引入的std::format的基础实现。它比传统的printf和iostream更安全、更灵活、性能更好。 基本介绍 主要特点 类型安全:…...