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