前端
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>分类展示页面</title><!-- 你可以在这里添加CSS样式链接,例如: --><!-- <link rel="stylesheet" href="/css/styles.css"> -->
</head>
<body><!-- 页面主体内容开始 --><div class="container"><!-- 分类列表开始 --><div class="category-list" th:if="${not #lists.isEmpty(categorys)}"><div class="item" th:each="category : ${categorys}"><h3><a href="#" th:href="@{/category/view(id=${category.id})}" th:text="${category.name}">分类名称</a></h3><div class="item-list clearfix" th:if="${not #lists.isEmpty(category.category2VoList)}"><div class="subitem" th:each="category2 : ${category.category2VoList}"><dl class="fore" th:if="${not #lists.isEmpty(category2.category3VoList)}"><dt><a href="#" th:href="@{/category/view(id=${category2.id})}" th:text="${category2.name}">子分类名称</a></dt><dd><em th:each="category3 : ${category2.category3VoList}"><a href="#" th:href="@{/category/view(id=${category3.id})}" th:text="${category3.name}">三级分类名称</a></em></dd></dl><!-- 如果没有三级分类,显示占位符 --><div th:unless="${not #lists.isEmpty(category2.category3VoList)}" class="no-subcategories"><p>暂无三级分类</p></div></div><!-- 如果没有二级分类,理论上这里不应该进入这个分支,因为上面的th:if已经检查了 --><!-- 但为了完整性,可以保留这个结构,并确保在数据准备时二级分类列表不为空 --></div><!-- 如果确实需要处理没有二级分类的情况(尽管逻辑上不应该),可以这样写: --><!-- <div th:unless="${not #lists.isEmpty(category.category2VoList)}" class="no-subcategories"> --><!-- <p>暂无二级分类</p> --><!-- </div> --></div></div><!-- 如果没有任何一级分类,显示占位符(这个通常不会在数据准备时发生,除非有特定逻辑) --><div th:unless="${not #lists.isEmpty(categorys)}" class="no-categories"><p>暂无分类信息</p></div><!-- 分类列表结束 --></div><!-- 页面主体内容结束 --><!-- 你可以在这里添加JavaScript脚本链接,例如: --><!-- <script src="/js/scripts.js"></script> -->
</body>
</html>
后端
private List<CategoryEntity> getParentId(List<CategoryEntity> selectList, Integer parentId) {return selectList.stream().filter(item -> item.getParentId().equals(parentId)) .collect(Collectors.toList());
}