MyBatis实现多表联合查询resultType的返回值
作者:aloofAnd 发布时间:2023-03-11 22:25:37
标签:MyBatis,查询,resultType,返回值
多表联合查询resultType的返回值
一般数据按参数类型返回
<select id="queryCarIdList" resultType="long">
select id from t_car_car
</select>
<select id="queryDept" resultType="string">
SELECT deptname FROM t_car_run where deptid = #{deptid} GROUP BY deptname
</select>
根据某字段查询
返回的类型是实体类,因为查询结果数据均为实体类中字段的数据
<select id="queryNumber" resultType="io.renren.modules.generator.entity.TCarRunEntity">
select number from t_car_car where id = #{carid}
</select>
查询结果为多条记录,存放在list中返回
返回的类型是实体类,因为查询结果数据均为实体类中字段的数据
<select id="queryCar" resultType="io.renren.modules.generator.entity.TCarCarEntity">
select * from t_car_car
</select>
多表联合查询
t_car_car
t_car_driver
t_car_cardriver
t_car_cardriver存放的两个字段分别是t_car_car和t_car_driver的主键id
解决方案
1.resultType的返回类型是java.util.Map
返回得到的是List中存放的所有数据
<select id="queryDriver" resultType="java.util.Map">
select driverid from t_car_cardriver where carid = #{id}
</select>
2.新建一个实体类
里面存放的是查询结果里需要的字段名
// TCarCarDriver
private Long carid;
private Long driverid;
返回类型为该实体类
<select id="queryDriver" resultType="TCarCarDriver">
select driverid from t_car_cardriver where carid = #{id}
</select>
多表联查,返回结果嵌套list
多层集合嵌套返回结果用resultMap,collection中再次使用resultMap
<resultMap id="chainVo" type="com.suncnpap.intelligentqa.vo.ChainVo">
<id column="cid" property="id"/>
<result column="access_key" property="accessKey"/>
<result column="secret_key" property="secretKey"/>
<result column="outer_chain_name" property="outerChainName"/>
<result column="outer_chain_document" property="outerChainDocument"/>
<collection property="intentionVos" ofType="com.suncnpap.intelligentqa.vo.ChainIntentionVo"
resultMap="intentionVos"/>
</resultMap>
<resultMap id="intentionVos" type="com.suncnpap.intelligentqa.vo.ChainIntentionVo">
<id column="iid" property="id"/>
<result column="intention_name" property="intentionName"/>
<collection property="questionVoList" ofType="com.suncnpap.intelligentqa.vo.MultiQuestionVo">
<id column="qid" property="id"/>
<result column="question" property="question"/>
</collection>
<collection property="wordVos" ofType="com.suncnpap.intelligentqa.vo.ChainIntentionWordVo">
<id column="wid" property="id"/>
<result column="word_slot" property="wordSlot"/>
<result column="word_slot_miss_question" property="wordSlotMissQuestion"/>
<result column="entity_type_ids" property="entityTypeIds"/>
</collection>
</resultMap>
<select id="detail" resultMap="chainVo">
select tc.id as tid,
tci.id as iid,
tciw.id as wid,
tmq.id as qid,
access_key,
secret_key,
outer_chain_name,
outer_chain_document,
intention_name,
question,
word_slot,
word_slot_miss_question,
entity_type_ids
from t_chain tc
left join t_chain_intention tci on tc.id = tci.chain_id
left join t_chain_intention_word tciw on tci.id = tciw.intention_id
left join t_multi_question tmq on tci.id = tmq.parent_id
where tc.id = #{id}
and tc.deleted = 0
</select>
来源:https://blog.csdn.net/weixin_44238871/article/details/106282507


猜你喜欢
- 概述用Time和Calendar获取系统当前时间(年月日时分秒周几)效果图源码:import android.app.Activity; i
- 搜索过滤功能,相信大家都能用到,一般都是针对列表进行过滤的。下面给大家提供一种过滤列表的方法。老规矩,先上图RecycleView搜索过滤器
- 安装完 Android Studio 后启动,却报错如下:failed to create jvm error code -4这一般应是内存
- 一、匿名结构体struct{ char name[20]; int age;}s1;匿名
- 先看看电影票在线选座功能实现的效果图:界面比较粗糙,主要看原理。这个界面主要包括以下几部分1、座位 2、左边的排数 3、左上方的缩略图 4、
- 本文实例为大家分享了Android自定义view贝塞尔曲线,供大家参考,具体内容如下贝塞尔曲线以一个简单的贝塞尔曲线为例,二阶曲线原理贝塞尔
- Spring Boot 2.7.6整合redis与低版本的区别最近在写程序的时候参考了之前写过的一篇文章spring boot整合redis
- 一、概述1、WebRequest:对统一资源标识符 (URI) 发出请求。 这是一个 abstract 类。WebRequest的派生类:P
- 目标了解HTTP 请求/响应头及常见的属性;了解如何使用SpringBoot处理头信息 ;了解如何使用SpringBoot处理Cookie
- 从GitHub下载GSON:https://github.com/google/gsonGson的应用主要为toJson与fromJson两
- 本文实例为大家分享了Android实现背景图片轮播的具体代码,供大家参考,具体内容如下点击按钮实现图片轮播效果实践案例:xml<?xm
- 这几天面试中有遇到关于main数组中的args数组传值的问题,一般是从命令提示符中传值,也可以直接在java代码中赋值。而且这个数组的长度是
- java 泛型方法:泛型是什么意思在这就不多说了,而Java中泛型类的定义也比较简单,例如:public class Test
- (鼠标放上去将一直显示,移开动画继续),提供normal和error两种边框。介绍:传统的确定,取消,OK,CANCAL之类的对话框太繁琐了
- 本文实例为大家分享了C#实现飞行棋小游戏的具体代码,供大家参考,具体内容如下逻辑图 以下是掷色子的一个代码,比较有代表性,里面的逻
- 本文实例讲述了C#动态创建button的方法。分享给大家供大家参考。具体实现方法如下:using System;using System.C
- 开始 在本文中,我将展示如何使用各种不同的 Java 技术构建一些简单的 Comet 风格的 Web 应
- (一) collection和collections这两者均位于java.util包下,不同的是:collection是一个集合接口,有Li
- Java中java.io包为我们提供了输入流和输出流,对文件的读写基本上都依赖于这些封装好的关于流的类中来实现。前段时间遇到了以下两种需求:
- 根据狂神的视频做的,然后自己优化了一些bug,比如新生成食物的时候不会生成在蛇的身体上,再新增长身体的时候不会在左上角出现一个绿色的方块以及