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 ...
随机推荐
- PIC16F877A.H头文件详细注释
/* * Header file for the Microchip * PIC 16F873A chip * PIC 16F874A chip * PIC 16F876A chip * PIC 1 ...
- 顺利通过EMC实验(11)
- SphinxJS——把字符串编码成png图片的超轻量级开源库
体验地址:https://jrainlau.github.io/sp...项目地址:https://github.com/jrainlau/s... SphinxJS 一个能够把字符串编码成png图片 ...
- css使Img图片居中显示
<div class="flex-center listing-img"> <img v-if="item.imgUrl" v-bind:sr ...
- ubuntu下Docker配置阿里云镜像加速
1.确认正确安装好docker,登录阿里云,打开如下界面 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 2.复制下面那段代码, ...
- Blazor技术开发了一个访客管理系统
简单介绍一下系统功能 该系统为了在疫情期间能很好管理访客登记做好风险管控,同时可以整合智能设备做到自动确认并跟踪访客的行动轨迹,该项目完全开源. 系统流程 访客可以同通过手机进行预注册,同时上传照片, ...
- numpy---(精简)
numpy get started 导入numpy库, 并查看版本 import numpy as np np.__version__ '1.14.3' # pyplot显示画图, 数据分析与可视化 ...
- 第一阶段:Java基础之控制结构
1.顺序结构 按照顺序控制结构运行,即语句从上到下,从左到右 2.选择结构 if..else..语句 switch..case..语句 3.循环结构 while循环 do...while & ...
- 使用JQGrid中可见列并存入Cookie
引入js与css <link href="~/Content/js/jquery-ui/jquery-ui.min.css" rel="stylesheet&quo ...
- window.history.go(-1);后退不刷新问题 移动端
在后退的界面上添加 判断是否是返回window.addEventListener('pageshow', function (e) { if(e.persisted || (window.per ...