search

Home  >  Q&A  >  body text

java - Do I need to set childrenID when setting parentID and ID in the database?

I want to traverse a tree recursively, but I feel that using parentID and ID cannot determine whether there are child nodes and cannot traverse it. I don’t know if I need to add a childrenID field

PHP中文网PHP中文网2763 days ago683

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-27 17:43:52

    If you only represent a tree, a single table of parentID and ID is enough; it is called: adjacency list.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-27 17:43:52

    Then add a treepath. Record the path from each node to the root node

    reply
    0
  • Cancelreply