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

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

相关文章:

  • 作用域的知识点总结
  • Day6 高精度加减算法+洛谷讲解
  • 开源RAG主流框架有哪些?如何选型?
  • 算法系列之分治算法
  • 从底层驱动到 OpenCV:深入解析 Linux 摄像头完整技术栈
  • 安全生产月安全知识竞赛主持稿串词
  • 基于Python和Neo4j开发的医疗辅助诊断系统的详细实现步骤和代码示例
  • Python--函数进阶(上)
  • Unity制作游戏——前期准备:Unity2023和VS2022下载和安装配置——附安装包
  • ESP32S3:解决RWDT无法触发中断问题,二次开发者怎么才能使用内部RTC看门狗中断RWDT呢?
  • 力扣热题100——滑动窗口
  • 【java】类和对象
  • 使用 AndroidNativeEmu 调用 JNI 函数
  • k8s学习记录:环境搭建(基于Kubeadmin)
  • 从入门到精通Rust:资源库整理
  • 【YOLOv11改进- 主干网络】YOLOv11+RepViT: 从ViT的角度重新审视Mobile的CNN助力YOLOv11有效涨点;
  • 解决Spring Boot中Druid连接池“discard long time none received connection“警告
  • DeepSeek R1的崛起与挑战:技术创新 与 普通人的反思
  • HTML之JavaScript DOM编程获取元素的方式
  • 制造业革命:数字化转型从哪里开始?
  • 两部门调度部署“五一”假期安全防范工作,要求抓好旅游安全
  • “女乘客遭顺风车深夜丢高速服务区”续:滴滴永久封禁两名涉事司机账号
  • 胸外科专家查出肺多发结节,说了一个可怕的事实……
  • 交通运输部:预计今年五一假期全社会跨区域人员流动量将再创新高
  • 金科股份:去年营收约275亿元,今年确保所有项目“零烂尾”
  • 十四届全国人大常委会第十五次会议继续审议民营经济促进法草案