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: