请教各位如何将树状图结构存入数据库并显示出来实现无穷级?(100分)

Z

zrning

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位如何将树状图结构存入数据库并显示出来实现无穷级?
 
任意叉树可以转化为二叉树,而二叉树又是可以线索的(serializable),就这思路。
 
two method.
1.use two fields that are parent id and child id to store the parent-child relation.
eg parent id , child id
-1 1
1 2
1 3
2 4

2.use two fields that are level and order
eg. level order
1 1
2 2
3 3
1` 4
2 5

the first method is good for manipulate the data, if you create a foreign key
for these two fields, remember add on delete cascade.then deleting the node of the tree
is quite easy.
but you have to use recursion to build the tree, it is slow.

the second method is good for build the tree, but the performance of manipulation is low.

so base on your system requirement to choice the suitable method
 
顶部