Java工作需求后端代码--实现树形结构

加油,新时代打工人!

前端页面
带树形结构的表格

最近在新项目上加班加点,下面是个实现树形结构的数据表格。

需求:

在前端页面表格中展示成树形结构的数据。

技术:

后端:Java、Mybatis-Plus、HuTool树形的工具类、Mysql

前端:Element UI

表结构

sql 复制代码
categoriyid	int(11)	NO	PRI		auto_increment
categoriycode	int(10)	YES	UNI		
categoriyname	varchar(50)	YES			
categoriyitemid	int(11)	YES			
status	int(2)	YES		0	
createtime	timestamp	YES		CURRENT_TIMESTAMP	DEFAULT_GENERATED
updatetime	timestamp	YES		CURRENT_TIMESTAMP	DEFAULT_GENERATED

HuTool工具类Jar

java 复制代码
<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.8.16</version>
</dependency>

Java实现类代码,用的Mybatis-plus,sql语句都省了

sql 复制代码
    @Autowired
	private CategoriyDao categoriyDao;
	@Override
	public List<Tree<Object>> getCategoriyList(CategoriyListVo categoriyListVo) {

		//1.没有条件查询所有的,可以根据自己的需求,加上查询条件,如查询状态已启用的
		QueryWrapper<CategoriyListVo> queryWrapper = new QueryWrapper<>();
		List<CategoriyListVo> dataList  = categoriyDao.selectList(queryWrapper);

		//2.配置
		TreeNodeConfig config = new TreeNodeConfig();
		config.setIdKey("id");      //默认id,可以不设置
		config.setParentIdKey("categoriyitemid");    //父id
		config.setNameKey("categoriyname");   //分类名称
		config.setDeep(2);      //最大递归深度
		config.setChildrenKey("children"); //孩子节点

		//3.转树
		List<Tree<Object>> treeList = TreeUtil.build(dataList, "0", config, ((object, treeNode) -> {
			treeNode.setId( object.getCategoriyid().toString());
			treeNode.setParentId(object.getCategoriyitemid().toString());
			treeNode.setName(object.getCategoriyname());
			//扩展字段
			treeNode.putExtra("categoriycode",object.getCategoriycode());//分类编码
			treeNode.putExtra("status",object.getStatus().toString());//状态
		}));
		return treeList;
	}

数据返回

相关推荐
LuckyTHP1 天前
迁移shibboleth java获取shibboleth用户信息
java·开发语言
客卿1231 天前
数论===质数统计(暴力法,)
java·开发语言
Σίσυφος19001 天前
C++ 多肽经典面试题
开发语言·c++·面试
华科易迅1 天前
Spring 事务(注解)
java·数据库·spring
写代码的小阿帆1 天前
Web工程结构解析:从MVC分层到DDD领域驱动
java·架构·mvc
东离与糖宝1 天前
Java 26+Spring Boot 3.5,微服务启动从3秒压到0.8秒
java·人工智能
csdn_aspnet1 天前
C# 求n边凸多边形的对角线数量(Find number of diagonals in n sided convex polygon)
开发语言·算法·c#
禹中一只鱼1 天前
【力扣热题100学习笔记】 - 哈希
java·学习·leetcode·哈希算法
凌波粒1 天前
LeetCode--349.两个数组的交集(哈希表)
java·算法·leetcode·散列表
qq_254674411 天前
Docker 中的 镜像(
开发语言