实体类:
import java.util.List;
public class TaskTypeConcatenationDto {
private Integer id;
private String title;
private List<TaskTypeConcatenationDto> taskTypeList;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<TaskTypeConcatenationDto> getTaskTypeList() {
return taskTypeList;
}
public void setTaskTypeList(List<TaskTypeConcatenationDto> taskTypeList) {
this.taskTypeList = taskTypeList;
}
}
mapper.xml文件:
<!--无条件或根据typeName模糊查询TaskType表的级联列表(一二三级)-->
<resultMap id="taskTypeConcatenationThreeDtoMap" type="com.studentHarbor.backstage.system.pojo.dto.TaskTypeConcatenationDto">
<id column="id" property="id"/>
<result column="title" property="title"/>
<collection property="taskTypeList" ofType="com.studentHarbor.backstage.system.pojo.dto.TaskTypeConcatenationDto" select="getTaskTypeTwoConcatenationListOfThree" column="id">
</collection>
</resultMap>
<!--无条件或根据typeName模糊查询TaskType表的级联列表(一二三级)-->
<resultMap id="taskTypeConcatenationThreeDtoMap2" type="com.studentHarbor.backstage.system.pojo.dto.TaskTypeConcatenationDto">
<id column="id" property="id"/>
<result column="title" property="title"/>
<collection property="taskTypeList" ofType="com.studentHarbor.backstage.system.pojo.dto.TaskTypeConcatenationDto" select="getTaskTypeThreeConcatenationListOfThree" column="id">
</collection>
</resultMap>
<!--一级-->
<select id="getTaskTypeOneConcatenationListOfThree" resultMap="taskTypeConcatenationThreeDtoMap" parameterType="com.studentHarbor.backstage.system.pojo.qo.TaskTypeQo">
SELECT
task_type.id,
task_type.typeName AS title
FROM
task_type
WHERE
task_type.deleted = 0 AND task_type.level = 1
<if test=" typeName != null and typeName != ''">
AND task_type.typeName LIKE CONCAT('%',#{typeName},'%')
</if>
</select>
<!--二级-->
<select id="getTaskTypeTwoConcatenationListOfThree" parameterType="int" resultMap="taskTypeConcatenationThreeDtoMap2">
SELECT
task_type.id,
task_type.typeName AS title
FROM
task_type
WHERE
task_type.deleted = 0 AND task_type.level = 2 AND task_type.parentId = #{id}
</select>
<!--三级-->
<select id="getTaskTypeThreeConcatenationListOfThree" parameterType="int" resultType="com.studentHarbor.backstage.system.pojo.dto.TaskTypeConcatenationDto">
SELECT
task_type.id,
task_type.typeName AS title
FROM
task_type
WHERE
task_type.deleted = 0 AND task_type.level = 3 AND task_type.parentId = #{id}
</select>
在swagger-ui.html上测试的结果如下:
{
"StatusCode": 0,
"Succeed": true,
"Message": "查询成功!",
"Data": {
"data": [
{
"id": 155,
"title": "高级管理",
"taskTypeList": [
{
"id": 156,
"title": "高级管理职位",
"taskTypeList": [
{
"id": 157,
"title": "CEO/总裁/总经理",
"taskTypeList": null
},
{
"id": 158,
"title": "副总裁/副总经理",
"taskTypeList": null
},
{
"id": 159,
"title": "事业部负责人",
"taskTypeList": null
},
{
"id": 160,
"title": "区域/分公司/代表处负责人",
"taskTypeList": null
},
{
"id": 161,
"title": "总裁/总经理/董事长助理",
"taskTypeList": null
},
{
"id": 162,
"title": "合伙人",
"taskTypeList": null
},
{
"id": 163,
"title": "创始人",
"taskTypeList": null
},
{
"id": 164,
"title": "董事会秘书",
"taskTypeList": null
}
]
}
]
}
],
"dataTotal": 1,
"pageTotal": 1
}
}