Java implementation to construct infinite hierarchical tree menu

Here, let's talk about how the background Java constructs a multi tree, so that the foreground can receive data and recursively construct a tree menu.

Let's take a look at how to realize the logic of constructing a multi fork tree. In fact, the whole problem can be summarized as follows

1. Construct an entity class to store nodes, so we need four objects (ID, PID, name, and childrenlist)

2. Construct menu structure

3. Construct a submenu and cycle through it, and judge the superior menu through PID

Specific implementation:

1. The tree is constructed here Java entity class

2. Encapsulate the tree structure class. Here I encapsulate it into a general tool class for easy use in projects. Menutreeutil Java, the complete code is as follows, which can be copied directly:

3. Finally, just request the method call data on the console. The method in the controller is as follows:

4. Then the foreground Ajax calls the interface method of the third part to request the required data. How to render a good foreground page, refer to my other article: vuejs uses recursive components to realize tree directory

That's all for the tree menu data constructed by Java. I hope it will be helpful to you. My sharing is generally particularly detailed. In addition to involving project privacy, I won't reserve it for you. I also hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>