A
A
Alexander2016-10-26 17:26:43
Java
Alexander, 2016-10-26 17:26:43

How to build a menu in java/jsp?

There was a difficulty in building the navigation menu on the site. I would like to make everything as beautiful as possible, but I could not find an example in java.
And so long ago:
There are 4 tables in the database for menu scalability:
Table1 (menu name): id, name, position;
Table2 (who is the parent (mapping menu to menu)): id, id_menuName, parents;
Table3(links): id, links;
Table4 (menu link mapping): id, id_menuName, id_links;

Here stackoverflow.com/questions/2871861/how-to-build-unlimited-level-of-menu-through-php-and-mysql saw a solution in the form of the hasChild() method, i.e. check if the second table in the parents column has the id that we are going to build and if so, extract it recursively, but the question arose:
if I, like foreach, will iterate through menuName, after I go through the nested menus, how can I not call them again.
Is there a tutorial on how to do it properly? Google at request on java menu offers me only manuals on awt/swing/FX.

Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Cheremisin, 2016-10-26
@leahch

We have already figured out how to build a menu, as I see it. If you haven’t figured it out, I advise the following approach, select all entries of all menus at once with one request, programmatically parse them and create a menu tree in a hashtable or xml.dom (I’m not kidding!, xpath rules here).
Next, you store the menu object in the servlet context or application context.
And do not climb into the database anymore, until the menu changes. If the menu has changed, then regenerate it again. Even if you have a menu of 65,000 items, which is unlikely, it will not take up much memory in any case.

A
Alexander, 2016-10-29
@ZzeroCool

And how crooked the solution will be: Fill the table into several java lists (which type the list has not yet decided) where the key is the id of the table. And then operate on the value of these lists. Everything is static (i.e. once accessed the database and hangs in the RAM).
About hashtable they write that it is better not to use the sim anymore.
Everything that is in Google about creating a menu is in php and comes down to an associative array with nesting. I'm trying to understand what solution will not be a crutch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question