欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 三级分类bug解决

三级分类bug解决

2025/2/25 8:40:50 来源:https://blog.csdn.net/m0_46695127/article/details/145798130  浏览:    关键词:三级分类bug解决

文章目录

  • 前端
  • 后端

前端

<!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)) // 使用 equals 比较 Integer,避免 NullPointerException.collect(Collectors.toList());// 如果需要返回 null 而不是空列表,可以添加以下判断:// if (result.isEmpty()) return null; else return result;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词