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

mybatis实现固定三层树形结构的嵌套查询

entity:

@Data
public class CategoryVo {private Long categoryId;  //当前分类idprivate String categoryName; //当前分类名private List<CategoryVo> categoryChild; //子分类
}

mybatis:

<resultMap id="CategoryTreeRM" type="com.atguigu.gmall.web.CategoryVo"><id property="categoryId" column="c1id"></id><result property="categoryName" column="c1name"></result><collection property="categoryChild" ofType="com.atguigu.gmall.web.CategoryVo"><id property="categoryId" column="c2id"></id><result property="categoryName" column="c2name"></result><collection property="categoryChild" ofType="com.atguigu.gmall.web.CategoryVo"><id property="categoryId" column="c3id"></id><result property="categoryName" column="c3name"></result></collection></collection>
</resultMap>
<select id="getCategorysTree" resultMap="CategoryTreeRM">select bc1.id   c1id,bc1.name c1name,bc2.id   c2id,bc2.name c2name,bc3.id   c3id,bc3.name c3namefrom base_category1 bc1left join base_category2 bc2 on bc2.category1_id = bc1.idleft join base_category3 bc3 on bc3.category2_id = bc2.id
</select>
http://www.dtcms.com/a/312993.html

相关文章:

  • 怎么修改论文格式呢?提供一份论文格式模板
  • 【ProtoBuf】初识ProtoBuf
  • 【UE5医学影像可视化】读取本地Dicom生成VolumeTexture,实现2D显示和自动翻页
  • 关于记录一下“bug”,在做图片上传的时候出现的小问题
  • B3953 [GESP202403 一级] 找因数
  • 大模型智能体(Agent)技术全景:架构演进、协作范式与应用前沿
  • Python Dash 全面讲解
  • 使用 Vuepress + GitHub Pages 搭建项目文档
  • io_getevents系统调用及示例
  • Android 之 图片加载(Fresco/Picasso/Glide)
  • 第四章:OSPF 协议
  • Docker环境离线安卓安装指南
  • Android 之 存储(Assets目录,SharedPreferences,数据库,内部存储等)
  • 音视频学习(五十):音频无损压缩
  • 使用 Docker 部署 Golang 程序
  • 计数组合学7.12( RSK算法的一些推论)
  • 考研复习-计算机组成原理-第二章-数据的表示和运算
  • PHP面向对象编程与数据库操作完全指南-下
  • 深入解析C++函数重载:从原理到实践
  • 2025年测绘程序设计比赛--基于统计滤波的点云去噪(已获国特)
  • MySQL梳理三:查询与优化
  • python新功能match case|:=|typing
  • Hertzbeat如何配置redis?保存在redis的数据是可读数据
  • 【MySQL安全】什么是SQL注入,怎么避免这种攻击:前端防护、后端orm框架、数据库白名单
  • Android设备认证体系深度解析:GMS/CTS/GTS/VTS/STS核心差异与认证逻辑
  • ELECTRICAL靶机复现练习笔记
  • Leetcode:1.两数之和
  • Java 大视界 -- Java 大数据机器学习模型在金融市场情绪分析与投资决策辅助中的应用(379)
  • ubuntu24.04安装selenium、edge、msedgedriver
  • 05.Redis 图形工具RDM