Java dynamically generates menus. Is there any good way to traverse jsp pages?

the jsp code is as follows, only traversing to level 3, level 4567 to continue to repeat the code is too much, is there a good solution?
having no parent id is a first-level menu, having a parent id without url is a second-level menu with child menus, and so on

< c:forEach items= "${menu}" var= "target" >

    <!-- parentId,url -->
    <c:if test="${empty target.parentId  and !empty target.url }">
        <li><a href="<c:url value="${target.url }"></c:url>"> <i
                class="${target.icon }"></i>${target.name }
        </a></li>
    </c:if>
    <!-- parentId,url -->
    <c:if test="${empty target.parentId  and empty target.url  }">
        <li><i class="${target.icon }"></i>${target.name }
            <ul>
                <c:forEach items="${target.childMenus }" var="childMenu">
                    <!-- url -->
                    <c:if test="${!empty childMenu.url }">
                        <li><a href="<c:url value="${childMenu.url }"></c:url>">
                                <i class="${childMenu.icon }"></i>${childMenu.name }
                        </a></li>
                    </c:if>
                    <!--  -->
                    <c:if test="${empty childMenu.url }">
                        <i class="${childMenu.icon }"></i>${childMenu.name }
                        <ul>
                            <c:forEach items="${childMenu.childMenus }" var="thirdMenu">
                                <!-- url -->
                                <c:if test="${!empty thirdMenu.url }">
                                    <li><a href="<c:url value="${thirdMenu.url }"></c:url>">
                                            <i class="${thirdMenu.icon }"></i>${thirdMenu.name }
                                    </a></li>
                                </c:if>
                                <!--  -->
                                <c:if test="${empty thirdMenu.url }">
                                    <c:forEach items="${thirdMenu.childMenus }" var="fourthMenu">
                                        <li>
                                            <a href="<c:url value="${fourthMenu.url }"></c:url>">
                                                <i class="${fourthMenu.icon }"></i>${fourthMenu.name }
                                            </a>
                                        </li>
                                    </c:forEach>
                                </c:if>
                            </c:forEach>
                        </ul>
                    </c:if>
                </c:forEach>
            </ul>
        </li>
    </c:if>
</c:forEach>


menu data:
Menu [id=1, name=Forms, parentId=, url=forms.html, icon=fa fa-edit, order=0, childMenus=null]
Menu [id=2, name=UI Elements, parentId=, url=, icon=fa fa-wrench, order=1, childMenus= [Menu [id=3, name=Buttons, parentId=2, url=buttons.html, icon=, order=0, childMenus=null], Menu [id=4, name=Icons, parentId=2, url=icons.html, icon=null, order=1, childMenus=null]
Menu [id=5, name=Multi-Level Dropdown, parentId=, url=, icon=fa fa-sitemap, order=2, childMenus= [Menu [id=6, name=Second Level Item, parentId=5, url=second.html, icon=null, order=0, childMenus=null], Menu [id=7, name=Third Level, parentId=5, url=null, icon=, order=1, childMenus= [Menu [id=8, name=Third Level Item, parentId=7, url=, icon=null, order=0, childMenus= [Menu [id=9, name=Fouth Level, parentId=8, url=fouth.html, icon=null, order=0, childMenus=null]

Database screenshot:

Mar.25,2021

use the tree plug-in and load it asynchronously. It's too troublesome to do this


with javascript


first transform the data structure into a tree, such as:

[{
   id:1,children:[{id:2,children:[]}]
},
{
  id:3,children:[{id:4,children...}]}...
]

then you can use recursive judgment to build a menu tree. The pseudo code is as follows:

buildTree(list){
  for(node in list){
     if(node.children){
         buildTree(node.children)
     }else{
         buildNode(node);
     }
  }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2c371-2baec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2c371-2baec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?