当前位置: 首页 > article >正文

三级分类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;
}

http://www.kler.cn/a/559557.html

相关文章:

  • YOLOv11-ultralytics-8.3.67部分代码阅读笔记-loaders.py
  • nextjs项目搭建——头部导航
  • 如何使用Python快速开发一个带管理系统界面的网站-解析方案
  • 【DeepSeek-R1背后的技术】系列十一:RAG原理介绍和本地部署(DeepSeek+RAGFlow构建个人知识库)
  • 游戏开发 游戏项目介绍
  • 深入解析浏览器渲染全流程:从URL输入到页面渲染的底层原理与性能优化(附实战代码)
  • seacms V9 SQL报错注入
  • Obsidian·Copilot 插件配置(让AI根据Obsidian笔记内容进行对话)
  • 【GPU驱动】OpenGLES图形管线渲染机制
  • PHP脚本示例
  • 【CSS】---- CSS 变量,实现样式和动画函数复用
  • 一种简单有效的分析qnx+android智能座舱项目中的画面闪烁的方法(8155平台)
  • vscode无法预览Markdown在线图片链接
  • 跟着李沐老师学习深度学习(十三)
  • 国产芯片汽车气压表pcba方案
  • AI学习之-阿里天池
  • React fiber架构中 优先级是如何确定的?
  • 【Bluedroid】AVRCP 连接源码分析(三)
  • 【NLP算法面经】本科双非,头条+腾讯 NLP 详细面经(★附面题整理★)
  • SOME/IP--协议英文原文讲解10