mybatis中resultMap标签中collection标签的嵌套使⽤mybatis中resultMap标签中collection标签的嵌套使⽤
场景
技能管理需要划分为
⼤类技能 (eg:演绎类)
⼦分类技能(eg:⽩蛇传)
技能(eg:⽩蛇技能、青蛇技能等)
表关系如下
⼤类—⼦类—技能
数据结构如下
"list":{
"classifySkillId":"eu",
"classifySkillName":"eiusmod cupidatat d",
人操人摸
"asmbleSkillLists":[
{
"asmbleSkillId":"incididunt ea es ad",
"asmbleSkillName":"adipisicing",
"nameSkillLists":[
{
"nameSkillId":"cupidatat",
"nameSkillName":"dolor aute dolor ut Duis"
},
{
"nameSkillId":"conctetur non dolore velit",
绑定英文
"nameSkillName":"Duis minim fugiat magna"
}
]
}
]
}
pojo类
@Data
public class SkillsManagerVo {
private String classifySkillId;
private String classifySkillName;
private List<AsmbleSkillListPo> asmbleSkillLists;
}
@Data
电脑开机时间查询public class AsmbleSkillListPo {
private String asmbleSkillId;
private String asmbleSkillName;
private List<NameSkillPo> nameSkillLists;
}
@Data
@TableName("name_skill")
化学行业
@AllArgsConstructor
@NoArgsConstructor
全屏手写public class NameSkillPo {
/**技能id*/
private String nameSkillId;
/**技能名称*/
private String nameSkillName;
/**⼦分类技能id*/
private String asmbleSkillId;
/**是否删除*/
private Integer deleted;
}
微信农场
查询的sql语句
<lect id="querySkills"resultMap="queryClassifySkills">
SELECT DISTINCT
s.classify_skill_id,
s.classify_skill_name,
s.asmble_skill_id,
s.asmble_skill_name,
ss.name_skill_id,
ss.name_skill_name
FROM
(
SELECT DISTINCT
cs.classify_skill_id,
cs.classify_skill_name,
asl.asmble_skill_id,
asl.asmble_skill_name
FROM
classify_skill cs
LEFT JOIN asmble_skill asl ON cs.classify_skill_id = asl.classify_skill_id
WHERE
cs.deleted = 0
AND asl.deleted = 0
ORDER BY
cs.classify_skill_id
) s
LEFT JOIN (
SELECT DISTINCT
年份五行
asl.asmble_skill_id,
asl.asmble_skill_name,
name_skill_id,
name_skill_name
FROM
asmble_skill asl
怎样才能变帅LEFT JOIN name_skill ns ON asl.asmble_skill_id = ns.asmble_skill_id
WHERE
asl.deleted = 0
AND ns.deleted = 0
ORDER BY
asl.asmble_skill_id
) ss ON s.asmble_skill_id = ss.asmble_skill_id
</lect>
resultMap的写法:collection标签中再嵌套collection就可以完成⼆级以上的集合嵌套;
<resultMap id="queryClassifySkills"type="entity.skillsmanager.vo.SkillsManagerVo">
<result column="classify_skill_id"property="classifySkillId"/>
<result column="classify_skill_name"property="classifySkillName"/>
<collection property="asmbleSkillLists"javaType="list"resultMap="nameSkills"
ofType="entity.skillsmanager.po.AsmbleSkillListPo"/>
</resultMap>
<resultMap id="nameSkills"type="entity.skillsmanager.po.AsmbleSkillListPo">
<result column="asmble_skill_id"property="asmbleSkillId"/>
<result column="asmble_skill_name"property="asmbleSkillName"/>
<collection property="nameSkillLists"javaType="list"ofType="entity.skillsmanager.po.NameSkillPo"> <result column="name_skill_id"property="nameSkillId"/>
<result column="name_skill_name"property="nameSkillName"/>
</collection>
</resultMap>
rty=“nameSkillId”/>