1、实体类

@Data
public class CourseChapterVO implements Serializable {
private static final long serialVersionUID = -67718827554034368L;
/**
* 主键ID
*/
private Integer id;
/**
* 课程ID
*/
private Integer courseId;
/**
* 课程章节名称
*/
private String chapterName;
/**
* 父ID
*/
private Integer chapterParent;
/**
* 层级
*/
private Integer chapterLevel; @JsonInclude(JsonInclude.Include.NON_EMPTY) //当children为空时不返回
private List<CourseChapterVO> children;
 }

2、mapper.xml

   <resultMap type="com.ruoyi.manager.vo.CourseChapterVO" id="CourseChapterMap2">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="courseId" column="course_id" jdbcType="INTEGER"/>
<result property="chapterName" column="chapter_name" jdbcType="VARCHAR"/>
<result property="chapterParent" column="chapter_parent" jdbcType="INTEGER"/>
<result property="chapterLevel" column="chapter_level" jdbcType="INTEGER"/>
<collection property="children" ofType="com.ruoyi.manager.vo.CourseChapterVO" column="id" select="selectListTree2"/>
</resultMap> <select id="selectListTree1" resultMap="CourseChapterMap2">
select id , course_id, chapter_name, chapter_parent, chapter_level
from course_chapter where chapter_parent =0 </select> <select id="selectListTree2" resultMap="CourseChapterMap2">
select id , course_id, chapter_name, chapter_parent, chapter_level from course_chapter where chapter_parent =#{id}
</select>

3、mapper.java

List<CourseChapterVO> selectListTree1(CourseChapter courseChapter);

4、serviceImpl.java

  @Override
public List<CourseChapterVO> queryAll(CourseChapter courseChapter) {
return this.courseChapterMapper.selectListTree1(courseChapter);
}

5、service.java

List<CourseChapterVO> queryAll(CourseChapter courseChapter);

6、controller.java

    @GetMapping("list")
public R queryAll(CourseChapter courseChapter) {
return R.data(this.courseChapterService.queryAll(courseChapter));
}

7、实现效果

{
"msg": "",
"code": 0,
"data": [
{
"id": 1,
"courseId": 5,
"chapterName": "第一章节学习",
"chapterParent": 0,
"chapterLevel": 1,
"children": [
{
"id": 2,
"courseId": 5,
"chapterName": "第一章节学习子1",
"chapterParent": 1,
"chapterLevel": 2
},
{
"id": 3,
"courseId": 5,
"chapterName": "第一章节学习子2",
"chapterParent": 1,
"chapterLevel": 2
},
{
"id": 4,
"courseId": 5,
"chapterName": "第一章节学习子3",
"chapterParent": 1,
"chapterLevel": 2
}
]
},
{
"id": 5,
"courseId": 5,
"chapterName": "第二章节学习",
"chapterParent": 0,
"chapterLevel": 1,
"children": [
{
"id": 6,
"courseId": 5,
"chapterName": "第二章节学习子",
"chapterParent": 5,
"chapterLevel": 2,
"children": [
{
"id": 9,
"courseId": 5,
"chapterName": "第二章节学习子1子1",
"chapterParent": 6,
"chapterLevel": 3
}
]
},
{
"id": 7,
"courseId": 5,
"chapterName": "第二章节学习子1",
"chapterParent": 5,
"chapterLevel": 2
},
{
"id": 8,
"courseId": 5,
"chapterName": "第二章节学习子2",
"chapterParent": 5,
"chapterLevel": 2
}
]
},
{
"id": 10,
"courseId": 5,
"chapterName": "第三章节学习gfdgdf",
"chapterParent": 0,
"chapterLevel": 1
}
]
}

最新文章

  1. CentOS安装运行NodeJS框架Express
  2. UI键盘通知
  3. DP:Dollar Dayz(POJ 3181)
  4. Kinect测量人体身高的程序
  5. Hyperic Agent 安装配置报 - No token file found, waiting for Agent to initialize
  6. LA3353
  7. C++递归求解N个元素的所有子集
  8. 第2章 Python基础语法 -- 数据类型
  9. X86 IO端口和MMIO
  10. Aizu - 0531 Paint Color
  11. Leetcode_116_Populating Next Right Pointers in Each Node
  12. Spring系列之手写一个SpringMVC
  13. Spring再接触 Annotation part2
  14. SAS 操作数据集的观测
  15. activiti 工作流 动态 设置 指定 节点任务人、责任人、组 的实现方式
  16. 【Java并发编程】12、ThreadLocal 解决SimpleDateFormat非线程安全
  17. Vue基础知识之组件及组件之间的数据传递(五)
  18. import 如何工作
  19. angularjs之事件绑定、解除事件绑定
  20. java分页实例Demo

热门文章

  1. case语法案例
  2. 浅谈 web3
  3. mysql函数实现oracle的序列
  4. web开发(1): html简介/ sublime text3使用/VScode使用
  5. appcrawler(2.1.3)采坑
  6. NXOpen拉伸
  7. [OC] Block 是什么
  8. 5. nginx跨域配置
  9. openGL 学习笔记 (一) 了解 OpenGL,创建第一个OpenGL窗口
  10. 最新go语言学习教程