基本类型数组

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 List属性 映射

mybatis 查询返回的类型中字段类型为 List<xx>的更多相关文章

  1. 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法

    使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,会报异常. 例如: <select id="getPersonRecordId" parameterTy ...

  2. SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int

    --SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int --关键说明:--1.从系统表syscolumns中的查询所有xtype='48'的记录得到类型为[tinyint]的字段- ...

  3. 数据库中字段类型对应的C#中的数据类型

    数据库中字段类型对应C#中的数据类型: 数据库                 C#程序 int int32 text string bigint int64 binary System.Byte[] ...

  4. 【网络收集】数据库中字段类型对应C#中的数据类型

    数据库中字段类型对应C#中的数据类型: 数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] bit Boolean cha ...

  5. 数据库中字段类型对应C#中的数据类型

    数据库中字段类型对应C#中的数据类型:数据库 C#程序 int int32 text string bigint int64 binary System.Byte[] bit Boolean char ...

  6. 数据库中字段类型对应的C#中的数据类型(转载)

    数据库中字段类型对应C#中的数据类型: 数据库                 C#程序 int int32 text string bigint int64 binary System.Byte[] ...

  7. schema中字段类型的定义

    当schema中字段类型为String时,保存的时候如果该字段为Number也可以保存成功,mongoose会自动将其转换为数字字符串. 当schema中字段类型为Number时,保存的时候如果该字段 ...

  8. Mysql中字段类型之时间戳大坑

         一 .环境说明: 在目前项目中,有这样的一张表,用来记录会议的相关信息,例如:会议的内容.会议的参会人员.会议的地点.会议的状态(会议是否已结束.会议是否被撤销).会议的开始时间以及该条信息 ...

  9. mybatis查询返回null解决方案

    mybatis查询返回null解决方案: 问题:查询出的列与javabean中的字段名不一致. 解决方案: 1.将javabean中的字段改为和查询出的列名一致: 2.将sql加入as改变列名,和ja ...

随机推荐

  1. 二十、生成BOM表

  2. 单页应用SPA开发最佳实践

    最近用vue+vue-router做了个单页应用的项目,页面大概有15个左右.积累了一些开发经验在此做一些记录.本文主要从可维护性方面来考虑SPA的开发实践 全站的颜色定义放在一个less或者scss ...

  3. 该如何选择 background-image 和 img 标签

    用img标签 如果你希望别人打印页面时候包含这张图片请使用 img 标签 当这张图片有非常有意义的语义,比如警告图标,请使用img标签及它的alt属性.这样意味着你可以向所有的用户终端现实他的意义. ...

  4. 将HTML页面转换为PDF文件并导出

    目前,在大多数的管理系统中,都会有这样一个功能:根据相关的条件查询相应的数据,并生成可视化报表,然后可导出为PDF文件.本文只展现生成可视化报表之后导出PDF文件的过程,生成可视化的报表可使用Echa ...

  5. 各种类型的Dialog

    下面是几种对话框的效果 图一: 图二: 图三: 图四: 图五: 图六: 图七: 图1效果:该效果是当按返回按钮时弹出一个提示,来确保无误操作,采用常见的对话框样式. 代码: 创建对话框方法dialog ...

  6. final,finally和finalize的区别

    package com.heima.test; public class Test1 {  /**  * * A:面试题1   * final,finally和finalize的区别   * fina ...

  7. LINUX执行shutdown.sh提示:-bash: ./startup.sh: Permission denied

    在执行./startup.sh,或者./shutdown.sh的时候,爆出了Permission denied, 其实很简单,就是今天在执行tomcat的时候,用户没有权限,而导致无法执行, 用命令c ...

  8. 微信小程序列表拖动排序Demo

    wxml页面编写 <view class="container"> <view bindtap="box" class="box&q ...

  9. 【版本2020.03】使用idea导入maven项目

    心得1:不同版本的idea,一些选项的名称稍微有点不同,比如以前导入项目的选项名称都是import Project,但是我使用的版本是2020.03 导入项目的名称是 import Settings ...

  10. Servlet实现登录注册

    1.注册页面register.html <!DOCTYPE html> <html lang="en"> <head> <meta cha ...