TreeNode实体类 key-菜单id title-菜单名称 parentId-父子菜单id cildren-子菜单
import java.util.List;
/**
* @Author forewei
* @date 2018-6-13 17:04
*/
public class TreeNode {
private Integer key;
private String title;
private Integer parentId;
private List<TreeNode> children;
public Integer getKey() {
return key;
}
public String getTitle() {
return title;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public void setTitle(String title) {
this.title = title;
}
public void setKey(Integer key) {
this.key = key;
}
public List<TreeNode> getChildren() {
return children;
}
public void setChildren(List<TreeNode> children) {
this.children = children;
}
}
Tree递归
5个方法实现递归树形结构
逻辑: 构建树形结构 —— 获取树形根菜单 —— 根据树形根菜单获取子菜单(递归调用)
/**
* 递归封装树形菜单
* @Author forewei
* @date 2018-6-22 11:49
*/
public class Tree {
List<TreeNode> nodes = new ArrayList<TreeNode>();
public Tree(List<TreeNode> nodes) {
super();
this.nodes = nodes;
}
/**
* 构建树形结构
*
* @return
*/
public List<TreeNode> buildTree() {
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
List<TreeNode> rootNodes = getRootNodes();
for (TreeNode rootNode : rootNodes) {
buildChildNodes(rootNode);
treeNodes.add(rootNode);
}
return treeNodes;
}
/**
* 递归子节点
*
* @param node
*/
public void buildChildNodes(TreeNode node) {
List<TreeNode> children = getChildNodes(node);
if (!children.isEmpty()) {
for (TreeNode child : children) {
buildChildNodes(child);
}
node.setChildren(children);
}
}
/**
* 获取父节点下所有的子节点
*
* @param nodes
* @param pnode
* @return
*/
public List<TreeNode> getChildNodes(TreeNode pnode) {
List<TreeNode> childNodes = new ArrayList<TreeNode>();
for (TreeNode n : nodes) {
if (pnode.getKey().equals(n.getParentId())) {
childNodes.add(n);
}
}
return childNodes;
}
/**
* 判断是否为根节点
*
* @param nodes
* @param inNode
* @return
*/
public boolean rootNode(TreeNode node) {
boolean isRootNode = true;
for (TreeNode n : nodes) {
if (node.getParentId().equals(n.getKey())) {
isRootNode = false;
break;
}
}
return isRootNode;
}
/**
* 获取集合中所有的根节点
*
* @param nodes
* @return
*/
public List<TreeNode> getRootNodes() {
List<TreeNode> rootNodes = new ArrayList<TreeNode>();
for (TreeNode n : nodes) {
if (rootNode(n)) {
rootNodes.add(n);
}
}
return rootNodes;
}
}
效果图
文章浏览阅读1.8w次,点赞3次,收藏13次。ArUco标记可以用于增强现实、相机姿势估计和相机校准等应用场景_aruco.hpp
文章浏览阅读1k次。问题描述:js在导出excel表格时身份证或数字过长会出现科学计数法,如E+13等。_js 导出身份证号码显示e+17
文章浏览阅读331次,点赞9次,收藏10次。插入一列快捷键:Ctrl+Shift+“+”
文章浏览阅读1.8k次,点赞9次,收藏9次。在Python中,你可以使用基本的打印语句和循环来绘制一个简单的圣诞树。每一行的空格数量会随着行号逐渐减少,而星号的数量则逐渐增加,形成圣诞树的形状。如果你想要一个更复杂的圣诞树,比如带有装饰和树干的,你可能需要使用一些图形库,比如。这个函数会打印出一个由星号(*)组成的圣诞树,树的高度由参数。但是,这需要更复杂的代码和更多的设置。
文章浏览阅读381次。执行webpack -v,却没返回版本消息PS E:\mango-ui> webpack -v ,CLI for webpack must be installed.webpack-cli (https://github.com/webpack/webpack-cli) We will use "npm" to install the CLI via "npm install -D webpack-cli".Do you want to install 'webpack-cli' (yes/no): _运行webpack -v 报错cli for webpack must be installed. webpack-cli
文章浏览阅读225次。高阶函数以函数作为参数/以函数作为返回值/常用于作为函数装饰器常用高阶函数:防抖Debounce和节流Throttlejs手写题——防抖和节流 Promise、setTimeout等等为什么要使用高阶函数?减少非纯函数的数量,增加系统稳定性与可靠性,纯函数方便做单元测试。函数柯里化函数式编程思想,既能减少代码冗余,也能增加可读性。它利用高阶函数,通过函数调用继续返回函数的形式,将接收多个参数转换为多次接收参数最后统一处理。理解函数柯里化function curry(fn,currArgs){_js 装饰器和高阶函数
文章浏览阅读1.4k次。使用Mecanim动画系统来控制2D动画原文:http://qinyuanpei.com/2015/02/11/unity2d-game-development-mecanim/今天我想和大家分享的话题是在Unity3D中使用Mecanim动画系统来控制2D动画。相信在大家的印象中,Mecanim动画系统主要运用在3D动画中,因为Mecanim动画系统提供了像动画重_2d动画重定向
文章浏览阅读983次,点赞28次,收藏31次。在我之前的博文里,将USB摄像头接入了香橙派并实现了垃圾类型识别;现在尝试将相同的USB摄像头接入树莓派!并测试拍照,视频流等功能,最后实现mjpg-streamer的开机自启功能!_在树莓派ros2中安装usb摄像头驱动
文章浏览阅读5次。import requestsfrom PIL import Imageimport jsonsrequests.packages.urllib3.disable_warnings()headers = { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like ..._12306验证 python
文章浏览阅读433次。1、vue解决了什么问题解决了用 DOM API 操作 UI 过于反人类的问题。React 通过 UI = f(data) 解决。Vue 通过 Reactive 响应式数据解决。更多关于上述问题理解2、MVVM的理解MVVM分为Model、View、ViewModel三者。Model:代表数据模型,数据和业务逻辑都在Model层中定义;View:代表UI视图,负责数据的展示;ViewModel:就是与界面(view)对应的Model。因为,数据库结构往往是不能直接跟界面控件一一对应上的_error with push/replace state domexception: failed to execute 'pushstate' on
文章浏览阅读1.9k次,点赞38次,收藏32次。P-Tuning v2的原理是通过对已训练好的大型语言模型进行参数剪枝,得到一个更加小巧、效率更高的轻量级模型。具体地,P-Tuning v2首先使用一种自适应的剪枝策略,对大型语言模型中的参数进行裁剪,去除其中不必要的冗余参数。然后,对于被剪枝的参数,P-Tuning v2使用了一种特殊的压缩方法,能够更加有效地压缩参数大小,并显著减少模型微调的总参数量。_chatglm微调自己的数据集
文章浏览阅读3.4k次。Table of Contents1 Introduction1.1 The Purpose of GNUgettext1.2 I18n, L10n, and Such1.3 Aspects in Native Language Support1.4 Files Conveying Translations1.5 Overview of GNUgettext2 Th_gnu gettext utilities