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

Mybatis集合嵌套查询,三级嵌套

三个表:房间 + 玩家 + 玩家信息 

知识点:Mybatis中级联有关联(association)、集合(collection)、鉴别器(discriminator)三种。其中,association对应一对一关系、collection对应一对多关系、discriminator可以根据情况选择采用哪个类作为实例,关联不同的结果集。

参考文章:Mybatis级联:关联、集合和鉴别器的使用 - aaron_shu - 博客园

# room.javaprivate List<Player> player;public List<Player> getPlayer(){return player;}public void setPlayer(List<Player> player){this.player = player;}
<resultMap type="Room" id="RoomResult"><id     property="roomId"       column="room_id"      /><result property="roomTitle"     column="room_title"    /><result property="roomOwnerId"     column="room_owner_id"    /><result property="roomTags" column="room_tags" /><result property="scoreMode"  column="score_mode" /><result property="qrCode" column="qr_code" /><result property="appId" column="app_id" /><result property="isPlaten" column="is_platen" /><result property="userId" column="user_id" /><result property="shopId" column="shop_id" /><result property="status"       column="status"       /><result property="delFlag" 		column="del_flag" /><result property="remark"       column="remark"       /><result property="createBy"     column="create_by"    /><result property="createTime"   column="create_time"  /><result property="updateBy"     column="update_by"    /><result property="updateTime"   column="update_time"  /><collection property="player"    javaType="ArrayList"  ofType="Player" resultMap="playerResult" /></resultMap><resultMap id="playerResult" type="Player"><result property="roomId"    column="room_id"       /><result property="playerScore"     	column="player_score"    /><result property="isOnlooker"     	column="is_onlooker"    /><result property="userId"     		column="user_id"    /><association property="customerUser" javaType="CustomerUser"  resultMap="customerUserResult" /></resultMap><resultMap id="customerUserResult" type="CustomerUser"><result property="userId"    	column="user_id"       /><result property="nickName"     column="nick_name"    /><result property="avatar"       column="avatar"       /></resultMap><sql id="selectRoomVo">select d.room_id, d.room_title, d.room_owner_id, d.score_mode, d.room_tags, d.qr_code,d.app_id, d.is_platen, d.del_flag, d.user_id, d.shop_id,p.player_score, p.is_onlooker, p.user_id,c.nick_name, c.avatar,d.remark, d.status, d.create_by, d.update_by, d.create_time, d.update_timefrom tb_room dleft join tb_player p on p.room_id = d.room_idleft join tb_customer_user c on c.user_id = p.user_id</sql>

前端得到的json结构

{"msg": "操作成功","code": 200,"data": {"createBy": "","createTime": "2025-03-06 12:15:09","updateBy": "",,"delFlag": "1","player": [{"createBy": null,"customerUser": {"createBy": null,"createTime": null, "avatar": "https://img1.baidu.com/it/u=2587875867,850432697&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800",}}]}
}

http://www.lryc.cn/news/547913.html

相关文章:

  • thinkphp5.1 在fetch模版就超时
  • Dockerfile 深入浅出:从基础到进阶全解析
  • CAD2025电脑置要求
  • android App主题颜色动态更换
  • 微服务,服务治理nacos,负载均衡LOadBalancer,OpenFeign
  • 浅论数据库聚合:合理使用LambdaQueryWrapper和XML
  • FastGPT 引申:混合检索完整实例
  • Socket.IO聊天室
  • MySQL表中数据基本操作
  • 可狱可囚的爬虫系列课程 16:爬虫重试机制
  • 第十五届蓝桥杯----B组cpp----真题解析(小白版本)
  • 软考架构师笔记-数据库系统
  • Spring AI 1.0.0-M6 快速开始(一)
  • go 分布式redis锁的实现方式
  • Unity中Stack<T>用法以及删除Stack<GameObject>的方法
  • Vue进阶之Vue3源码解析(二)
  • linux的文件系统及文件类型
  • 如何下载安装 PyCharm?
  • 3D空间曲线批量散点化软件V1.0正式发布,将空间线条导出坐标点,SolidWorks/UG/Catia等三维软件通用
  • WPS AI+office-ai的安装、使用
  • java后端开发day27--常用API(二)正则表达式爬虫
  • 拼电商客户管理系统
  • 华为:Wireshark的OSPF抓包分析过程
  • Android项目优化同步速度
  • 在线教育网站项目第二步 :学习roncoo-education,服务器为ubuntu22.04.05
  • STM32-GPIO详解
  • 【Framework系列之Client】UIManager和UIPanel模块介绍
  • 阿里云操作系统控制台——ECS操作与性能优化
  • 【长安大学】苹果手机/平板自动连接认证CHD-WIFI脚本(快捷指令)
  • 第51天:Web开发-JavaEE应用SpringBoot栈身份验证JWT令牌Security鉴权安全绕过