使用深度在Java中将树的嵌套集合模型嵌套

时间:2019-03-18 06:28:51

标签: java depth nested-set-model

关于管理分层数据Nested Set Model,我们能够找到以下节点的深度

SELECT node.name, (COUNT(parent.name) - 1) AS depth
FROM nested_category AS node,
    nested_category AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.name
ORDER BY node.lft;

结果

+----------------------+-------+ | name | depth | +----------------------+-------+ | ELECTRONICS | 0 | | TELEVISIONS | 1 | | TUBE | 2 | | LCD | 2 | | PLASMA | 2 | | PORTABLE ELECTRONICS | 1 | | MP3 PLAYERS | 2 | | FLASH | 3 | | CD PLAYERS | 2 | | 2 WAY RADIOS | 2 | +----------------------+-------+

有没有可用于Java的API,可以根据此结果构建树?或什么数据结构适合于此?

0 个答案:

没有答案