Domanda

I used tomahawk tree2 component to display directory structure in a JSP page. I have maintained parent and child folder relationship in a database table. Example DB table looks as below. Where field values represents folder ID's

When i pass 7 as PARENT_FOLDER_ID to the table i get 87 and 587 as it's sub-folders. Again 87 and 587 contains 6067 and 12704 as their sub-folders. This example only has 2 level relationship.

I need to traverse this relationship until last sub-folder(Which doesn't contains folders.From the example 2117, 2177, 2312, 2379, 6067, 12704 are last folders.). How to achieve this traversing process in java. Please help me to find the solution.

Thank you.

È stato utile?

Soluzione

Recursive approach:

public void processChilds(int parentID) {
List childs=selectChilds(parentID);//call method which return list of sub folders of the parameter
for(int i=0;i<childs.size();i++) {
    processChilds(childs.get(i));//call processChilds() for each child
    }
}

And Implement the selectChilds(int parentID) as your requirement and that must return list of sub folders.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top