mybatis 查询返回的类型中字段类型为 List<xx>
基本类型数组
mapper.xml
<resultMap id="xxDtoResultMap"
type="com.xx.xxDto">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="roomCount" column="room_count" jdbcType="INTEGER"/>
<collection property="roomIds" ofType="Integer">
<result column="room_ids"/>
</collection>
</resultMap>
<select id="list" resultMap="xxDtoResultMap">
select
id
count(xx.id) as room_count,
room.id as room_ids
....
</select>
自定义类型数组
Vo
package cn.myesn.pojo.vo;
import lombok.Data;
import java.util.List;
/**
* 二级分类 VO
*/
@Data
public final class CategoryVo {
private Integer id;
private String name;
private String type;
private Integer fatherId;
private List<SubCategoryVo> subCategories;
@Data
public static final class SubCategoryVo{
private Integer subId;
private String subName;
private String subType;
private Integer subFatherId;
}
}
mapper.xml
<resultMap id="myCategoryVo" type="cn.myesn.pojo.vo.CategoryVo">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="INTEGER" />
<result column="fatherId" property="fatherId" jdbcType="INTEGER" />
<collection property="subCategories" ofType="cn.myesn.pojo.vo.CategoryVo$SubCategoryVo">
<id column="subId" property="subId" jdbcType="INTEGER" />
<result column="subName" property="subName" jdbcType="VARCHAR" />
<result column="subType" property="subType" jdbcType="INTEGER" />
<result column="subFatherId" property="subFatherId" jdbcType="INTEGER" />
</collection>
</resultMap>
<select id="getSubCategories" resultMap="myCategoryVo" parameterType="int">
select
f.id as id,
f.name as name,
f.`type` as `type`,
f.father_id as fatherId,
c.id as subId,
c.name as subName,
c.`type` as subType,
c.father_id as subFatherId
from category f
left join category c on f.id = c.father_id
where f.father_id = #{rootCategoryId}
</select>
参考
select-list-of-integers-as-collection-inside-another-result-map-in-mybatis
mybatis 查询返回的类型中字段类型为 List<xx>的更多相关文章
- 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法
使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,会报异常. 例如: <select id="getPersonRecordId" parameterTy ...
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
--SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int --关键说明:--1.从系统表syscolumns中的查询所有xtype='48'的记录得到类型为[tinyint]的字段- ...
- 数据库中字段类型对应的C#中的数据类型
数据库中字段类型对应C#中的数据类型: 数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] ...
- 【网络收集】数据库中字段类型对应C#中的数据类型
数据库中字段类型对应C#中的数据类型: 数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] bit Boolean cha ...
- 数据库中字段类型对应C#中的数据类型
数据库中字段类型对应C#中的数据类型:数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] bit Boolean char ...
- 数据库中字段类型对应的C#中的数据类型(转载)
数据库中字段类型对应C#中的数据类型: 数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] ...
- schema中字段类型的定义
当schema中字段类型为String时,保存的时候如果该字段为Number也可以保存成功,mongoose会自动将其转换为数字字符串. 当schema中字段类型为Number时,保存的时候如果该字段 ...
- Mysql中字段类型之时间戳大坑
一 .环境说明: 在目前项目中,有这样的一张表,用来记录会议的相关信息,例如:会议的内容.会议的参会人员.会议的地点.会议的状态(会议是否已结束.会议是否被撤销).会议的开始时间以及该条信息 ...
- mybatis查询返回null解决方案
mybatis查询返回null解决方案: 问题:查询出的列与javabean中的字段名不一致. 解决方案: 1.将javabean中的字段改为和查询出的列名一致: 2.将sql加入as改变列名,和ja ...
随机推荐
- 学习Kvm(六)
五,管理虚拟存储 5.1 虚拟磁盘概述 5.1.1 虚拟化项目中存储的注意事项 [x] 存储的性能几乎总是虚拟化的瓶颈 [x] 通过多个硬盘驱动以分布磁盘I/O来实现存储解决方案 [x] 考虑部署集中 ...
- (stm32学习总结)—spi基本原理
参考:spi详解 spi协议 SPI的基本介绍 SPI的简介 SPI,是英语Serial Peripheral interface的缩写,顾名思义就是串行外围设备接口,是Motorola首先在其M ...
- js 关于setTimeout和Promise执行顺序问题
js 关于setTimeout和Promise执行顺序问题 异步 -- Promise和setTimeout 执行顺序 Promise 和 setTimeout 到底谁先执行 定时器的介绍 Jav ...
- 实现自定义的小程序底部tabbar
背景 诶,当然是为了实现更有温度的代码啦(背后设计师拿着刀对着我) 自带tabbar app.json中配置: tabBar: { backgroundColor: '#fff', borderSty ...
- 订单突破10000+,仅花1小时,APPx独家深入剖析背后的秘密!
拼多多:成立三年,获客三亿,月订单成交额达到恐怖的400亿,成功上市! 糕妈优选:营销活动推送1小时,订单超过10000+,商品成功刷屏朋友圈! 寻慢:一场活动净增7000+粉丝,付款转化率高达71% ...
- java堆排序
直接贴源代码: package com.java.fmd; import java.util.Scanner; public class HeapSort { int[] arr; public st ...
- java中请给一个Abstract类实现接口的实例!
2.Abstract类实现接口 马克-to-win:如果实现某接口的类是abstract类,则它可以不实现该接口所有的方法.但其非abstract的子类中必须拥有所有抽象方法的实在的方法体:(当然它a ...
- HTML 和 form 表单常用标签
HTML和CSS 常用标签: p:段落,自动换行 span:和div类似,但是默认不换行 br:换行 hr:分割线 h1-h6:标题标签 a:超链接 瞄点:通过给a链接设置#XX作为链接,给需要链接的 ...
- Mybatis的简介+简单实现增删改查案例
@ 目录 总结内容 1. 基本概念 2. Mybatis的使用 需求 配置文件简介 总结 总结内容 1. 基本概念 Mybatis是一款优秀的持久层框架,它支持定制化SQL.存储过程以及高级映射.My ...
- 制作java的docker镜像
Dockerfile如下: FROM ubuntu:16.04 MAINTAINER tanyiqu ADD jdk-8u231-linux-x64.tar.gz /usr/local/ ENV JA ...