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 ...
 
随机推荐
- BMZCTF phar???
			
pchar??? 补充知识点 开始这题之前我们先补充一个知识点 phar 的文件包含 和上面类似先创建一个phar 标准包,使用 PharData 来创建,然后添加文件进去phar里面. 然后在文件包 ...
 - 攻防世界NewsCenter
			
NewsCenter 打开题目是一个搜索框我们首先尝试一下sql注入 判断了一下是使用''进行包裹的字符型sql注入 然后我们需要判断数据库列数 1' order by 3# 回显正常但by4的时候回 ...
 - 关于elementUI如何在表格循环列表里分别新增Tag的设计使用
			
话不多说,直接上代码.想要实现的目的是这样的,想要在表格里单独添加每一个tag 那么,需要解决的问题就是如何定义这每一个插槽里的输入框,把每个输入框以及里面插入的数据区分开. 研究了很久,最后选择了对 ...
 - Linux中一切皆文件
			
谈一谈Linux中一切皆文件 1. Linux中所有内容都是以文件的形式保存和管理,即:一切皆文件. 普通文件是文件. 目录(在win下称为文件夹)是文件. 硬件设备(键盘.硬盘.打印机)是文件. 套 ...
 - Altium Designer 原理图的绘制前导
			
元件库.封装库设计 部分元器件厂商或者经销商不提供元件库和封装库,只给了元器件尺寸图,所以需要自行设计元件库文件或是封装库文件 元件库设计: 新建 .SchLib 文件:File -> N ...
 - IPhoneX网页布局简介
			
IPhoneX全面屏是十分科技化的,但是由于其圆角和摄像头刘海位置以及操控黑条的存在使得我们需要去对其样式做一些适配,没有X的同学可以开启 Xcode 9 的iPhone X 模拟器作为学习和调试. ...
 - 【HTML5版】导出Table数据并保存为Excel
			
首发我的博客 http://blog.meathill.com/tech/js/export-table-data-into-a-excel-file.html 最近接到这么个需求,要把<tab ...
 - 所有用CSS3写的3D特效,都离不开这些知识
			
起因 昨晚在做慕课网的十天精通CSS3课程,其中的综合练习是要做一个3D导航翻转的效果.非常高大上. 以往这些效果我都很不屑,觉得网上一大堆这些特效的代码,复制粘贴就好了,够快.但是现实工作中,其实自 ...
 - Linux 0.11源码阅读笔记-内存管理
			
内存管理 Linux内核使用段页式内存管理方式. 内存池 物理页:物理空闲内存被划分为固定大小(4k)的页 内存池:所有空闲物理页组成内存池,以页为单位进行分配回收.并通过位图记录了每个物理页是否空闲 ...
 - java中操作符的用法
			
5.操作符 public class Test{ public static void main(String[] args){ int i, k; i = 10; /*下面 ...