基本类型数组

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

最新文章

  1. h264码流分析
  2. SilkTest天龙八部系列1-初始化和构造函数
  3. show drop down menu within/from action bar
  4. input type=file accept中可以限制的文件类型
  5. Linux重装系统后SSH登录失败
  6. add BOM to fix UTF-8 in Excel
  7. VB2012读取xml
  8. win7系统下连接使用mac 蓝牙键盘(Apple Wireless Keyborad)
  9. 两台linux机器时间同步
  10. WPF InkCanvas 画图 基础使用教程
  11. django restframework serializer 增加自定义字段
  12. windbg蓝屏调试
  13. CFUpdate高速模式下出现Error #2038提示的解决方案
  14. 关于FFmpeg工具的使用总结
  15. T-SQL :SQL Server系统数据库(二)
  16. 进程池原理及效率测试Pool
  17. svn使用小技巧
  18. Voronoi图与Delaunay三角剖分
  19. 转:ios Sqlite数据库增删改查基本操作
  20. vue中上传文件相同文件名没反应

热门文章

  1. 攻防世界 ics-06
  2. fsdfd
  3. Content Security Policy减少劫持
  4. 体验js之美第八课-面向对象创建和继承终结篇
  5. 初识JavaScript EventLoop
  6. HTML 初学整理
  7. javaweb之浏览功能
  8. ubantu之Git使用
  9. centos7 装机后的基本配置
  10. 状态机引擎在vivo营销自动化中的深度实践 | 引擎篇02