java 处理树形结构数据

前言

问题的背景大概是这样的,有下面这样一个excel表,原始数据结构如下:

需求点:

  • 导入excel的机构层级数据到mysql的机构表(这里假设为 depart);
  • 导入的机构数据以层级进行保存和区分;
  • 界面展示时需要以完整的树形层级进行展示;

处理过程

按照上面已知的信息,设计一个简单的机构表

CREATE TABLE `depart` (
  `depart_id` varchar(64) DEFAULT NULL,
  `pid` varchar(64) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `path` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

接下来分析下具体的实现;

1、导入的时候以层级保存数据 

有做过树形结构处理业务的小伙

JAVA - 4行代码实现省市区三级树形结构 思路 无脑把省市区单独从数据库拿出来,然后通过分组组合成一颗树。由于这不能连数据库,所以得模拟些数据。 先新建个实体类 @Data @Accessors(chain = true) public class CityTreeVo { //父类ID private Integer parentId; //ID private Integer id; //名称 private String name; //子类 private List<CityTreeVo&g 阅读详情

相关推荐

使用Java实现通用树形结构转换工具类:深入解析TreeUtil和TreeNode接口

实现一个通用的树形结构转换工具类`TreeUtil`,以及如何定义一个灵活的节点接口`TreeNode`.构建`TreeUtil`类,使用它将扁平的数据集合转换为树形结构

huangyanhua616的博客 1411

java遍历机构和菜单树形结构数据

查询机构数据结构数据 mapper层接口省略 /** &amp;amp;lt;一句话功能简述&amp;amp;gt;查询机构树形机构返回数据 &amp;amp;lt;功能详细描述&amp;amp;gt; @author DENG @version [版本号, 2018年11月1日] @see [相关类/方法] @since [产品/模块版本] */ public class ResOrgDto { private String orgCo...

Lotus 2458

poi从excel中读取父子关系型(树形)数据结构到数据库

poi从excel中读取父子关系型(树形)数据结构到数据库

huilangeliuxin的专栏 8809

java工程积累——树形结构的操作

通过这几天的观察,我们发现,集体的智慧永远是最强大的,每个人贡献一点点,我们就能将问题的解决方案在设计之初就升级到一个客观的程度,包括这次的树形结构的研究,相信你的队友不论他在你心理到底是什么状态,他既然被招进公司,肯定有他的闪光点打动了人力部门,且还有一句话,高手在民间,这句话,已经多次被验证了! 子段:i

ESOO 5415

java 基于poi 写入excel 合并单元格

效果图如下: 提供个人的一些想法,大牛不要看 (1)对于要写入的数据,树形结构,构建临时类,嵌套,如下图(类似即可) public class ValueObj { private String areaName = "";//名称 private String areaId; private int colspan = 1;//该数据占有的

白水的博客 1015

Hutool 使用TreeUtil工具解决树形结构

树形结构代码来源:https://blog.youkuaiyun.com/Anenan/article/details/113029547 工具类代码来源:https://www.cnblogs.com/liangweiping/archive/2020/04/28/12792418.html pom.xml的依赖 <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all --> <dependency

weixin_40140969的博客 4752

Java根据选中子节点递归返回跟节点

返回所有选中的根目录即。

太阳 665

java8 lambda表达式递归查询树形结构

@Override public List<DeviceGroupVo> getDeviceGroup() { //查询全部 List<DeviceGroupVo> deviceGroup = deviceGroupDao.getDeviceGroup(); List<DeviceGroupVo> collect = deviceGroup.stream() .filter(item.

weixin_44942563的博客 1993

java生成easyui-tree返回easyui-tree类型的json数据

这里写自定义目录标题树的数据格式(Tree Data Format)Service层 树的数据格式(Tree Data Format) tree数据类型的介绍来自Easyui Tree树 EasyUi插件 id:节点的 id,它对于加载远程数据很重要。 text:要显示的节点文本。 state:节点状态,‘open’ 或 ‘closed’,默认是 ‘open’。当设置为 ‘closed’ 时,该...

unowen的博客 1061

java使用递归将查询的数据转JSON树状结构数据

java使用递归将查询的数据转JSON树状结构数据 1.第一种情况,从数据库中查出数据如下: 使用以下代码进行转换,先提取pId为0的父节点,再把子节点递归提取出来 `public static List<Map> toTreeByMap(List<Map> list) { List<Map> treeList = new ArrayList<>(); for (Map tree : list) { i

qq_42807116的博客 1033

java 实现导出到Excel 的数据按照树形结构排列

首先 讲下需求 工作中遇到的,要求从一个功能中导出一堆会员数据,这些会员是有层级结构的,有推荐关系的那种 后台中是以树形展示的 但是导出到excel如何也实现这种树形排列呢 ? 发现POI可以实现这个功能 特别感谢谷歌 根据谷歌的知识汇总 的启发自己实现了这个功能 支持无线层级的树形结构 import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; impor...

koproblem的专栏 3563

树形结构数据还原成普通list,根据父类id获得所有子孙后代id集合方法实现

说明 代码是自己项目中的部分代码,对于小白可能不太友好,容易看不太懂,代码其实不是很重要,重要的是设计思路,比如我们做的java三大排序算法的时候,和打印菱形、五角星图案时候,只要自己明白的了设计思路,代码写起来就容易多了。 下面代码实现的思路还是,通过不断循环自身的方法,知道下级没有数据或者为null时,结局遍历循环。 树形结构数据中,根据父类id获取子孙后代id集合和 树形结构数据还原成普通list集合方法 /** * *获得下级子类id集合 ...

洛阳泰山的博客 2806

DETR系列文章之–Co-DETR

Co-DETR,并行训练多个辅助头,以一对多的标签分配方式进行监督从辅助头中提取正样本坐标,为解码器中的正样本的训练效率进行额外的定制化正样本query.一对一标签分配:每个GT框分配给一个特定的query(DETR),较少的正query导致低效训练,从编码器生成的潜在表示和解码器中的注意力学习分析这一问题。一对多标签分配:每个GT框分配给检测器输出的多个proposal/anchor,依赖NMS或者anchor生成(ATSS,RetinaNet,FCOS,PAA)。

weixin_43731232的博客 2103

让Claude连续写代码24小时会发生什么?揭秘长时运行”架构背后的工程逻辑与未来

AI长时运行实验揭示软件开发新范式 Claude Opus通过Harness框架24小时独立开发全栈应用的成功实验,展示了AI从辅助工具向异步协作者的进化。实验采用"上下文轮转"机制解决记忆管理难题,将任务拆解为微周期并通过文件系统同步进度。核心突破在于:1)TDD成为AI自治基石,200+测试用例确保开发不偏航;2)文件取代对话成为AI间高效沟通介质;3)开发者角色重构为需求定义和框架设计者。该实验证明,通过严谨的架构约束和验收标准,AI可完成复杂长周期任务,预示着软件开发将从手工作坊

老孙 | Ethan Sun 的博客:AI 智能体与 AI 原生软件的工程实践 1091

【Niagara Vykon N4 】物联网学习 03照明控制及照明时间表

3.1 设计思路 3.2逻辑组件添加 ①依据原有控制照明逻辑,打开palette,找到schedule模块,添加BoolenSchedule。 ②打开kitContrl,找到Util,并添加BoolenSwitch。 ③剪切到原有的逻辑线,并进行逻辑连接,如下图。 ④新建BooleanWritable,命名为Switch,设置参数并进行逻辑连接,若下图。 3.3界面设计 ⑤至此完成了逻辑的设...

weixin_45217107的博客 2863

matlab电偶极子源码,电偶极子的MATLAB场模拟

电偶极子周围电场电势分布的MATLAB三维模拟Matlab可以用于模拟四维场的效果,本文以电偶极子的电场和电势场为例展示MATLAB在该方面领域的应用。摘要电偶极子由一个正电荷和一个负电荷组成,其电场和空间电势分布与单电荷相比具有一些重要的特性。本文将给出电场和电势场的近似表达式。这两个量的精确表达式是复杂的,不太常用,因此 MATLAB 被采用来操作精确值和绘制三维分布的远区域, 近区域和一侧区...

weixin_35135480的博客 3150

别再瞎调参数了!用MATLAB fmincon优化傅里叶级数,为你的机器人设计“完美”激励轨迹

本文详细介绍了如何利用MATLAB的fmincon优化器设计机器人激励轨迹,通过优化傅里叶级数参数,解决传统试错法的低效问题。文章涵盖了目标函数设计、约束条件转化及优化算法选择,帮助工程师实现高精度的系统辨识和动力学参数优化。

weixin_42613501的博客 240

生产环境中redis的SCAN命令如何替代KEYS命令?

本文介绍了使用SCAN命令替代KEYS的完整方案。SCAN通过游标分批迭代,避免KEYS命令遍历整个键空间导致的阻塞风险。文章详细说明了SCAN的基础语法、迭代流程和Java实现示例,强调必须关闭Cursor避免连接泄漏。针对生产环境,提供了COUNT参数调优、客户端去重、集群模式适配等优化建议,并列举了典型错误场景。SCAN通过分批次迭代和游标管理,可安全实现高性能键空间遍历。全文150字。

DN金猿的博客 179

ESP32-C3蓝牙透传通信的BLE协议栈工程实践

蓝牙低功耗(BLE)透传是一种基于GATT服务模型的数据透明传输机制,其核心原理在于Peripheral设备通过广播建立连接,并在GATT Server层暴露可读写特征值实现双向数据通道。该技术具备低功耗、跨平台兼容性强、开发门槛适中等优势,广泛应用于智能硬件、工业传感器与嵌入式网关等场景。在实际工程中,透传稳定性高度依赖BLE协议栈的分层协同——Link Layer负责可靠连接建立,GATT Server则定义数据交互语义;而ESP32-C3的AT指令集正是对这两层能力的封装调度。本文聚焦BLE透传的关键

weixin_29859471的博客 123

Dify平台隐患url:/console/api/remote-files/upload暴露高危漏洞,配置nginx htpasswd模块认证机制屏蔽解决

内部网络探测: 攻击者可通过SSRF扫描内网服务云元数据访问: 可能访问AWS/Aliyun/腾讯云等元数据服务服务端请求伪造: 以服务器身份发起任意HTTP请求。

CN_Eden 1317

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

上一篇: redis 哨兵集群搭建
下一篇: Redis 键值设计使用总结
逆风飞翔的小叔
逆风飞翔的小叔 新星创作者: 大数据技术领域 新星创作者: 大数据技术领域
博客等级 码龄5年 1万+粉丝 215原创
评论 55
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逆风飞翔的小叔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值