讲师详情页
# 一、后端
# 1、CourseService
根据讲师id查询讲师所讲课程列表
接口
List<Course> selectByTeacherId(String teacherId);
1
实现
/**
* 根据讲师id查询当前讲师的课程列表
* @param teacherId
* @return
*/
@Override
public List<Course> selectByTeacherId(String teacherId) {
QueryWrapper<Course> queryWrapper = new QueryWrapper<Course>();
queryWrapper.eq("teacher_id", teacherId);
//按照最后更新时间倒序排列
queryWrapper.orderByDesc("gmt_modified");
List<Course> courses = baseMapper.selectList(queryWrapper);
return courses;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 2、TeacherController
@Autowired
private CourseService courseService;
1
2
2
修改getById方法:
@ApiOperation(value = "根据ID查询讲师")
@GetMapping(value = "{id}")
public R getById(
@ApiParam(name = "id", value = "讲师ID", required = true)
@PathVariable String id){
//查询讲师信息
Teacher teacher = teacherService.getById(id);
//根据讲师id查询这个讲师的课程列表
List<Course> courseList = courseService.selectByTeacherId(id);
return R.ok().data("teacher", teacher).data("courseList", courseList);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 3、swagger测试
# 二、前端详情js
# 1、teacher api
api/teacher.js
getById(teacherId) {
return request({
url: `${api_name}/${teacherId}`,
method: 'get'
})
}
1
2
3
4
5
6
2
3
4
5
6
# 2、讲师详情页中调用api
pages/teacher/_id.vue
<script>
import teacher from "@/api/teacher"
export default {
asyncData({ params, error }) {
return teacher.getById(params.id).then(response => {
console.log(response);
return {
teacher: response.data.data.teacher,
courseList: response.data.data.courseList
}
})
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
#
# 三、页面渲染
# 1、讲师基本信息模板
<template>
<div id="aCoursesList" class="bg-fa of">
<!-- 讲师介绍 开始 -->
<section class="container">
<header class="comm-title">
<h2 class="fl tac">
<span class="c-333">讲师介绍</span>
</h2>
</header>
<div class="t-infor-wrap">
<!-- 讲师基本信息 开始 -->
<!-- /讲师基本信息 结束 -->
<div class="clear"/>
</div>
<section class="mt30">
<div>
<header class="comm-title all-teacher-title c-course-content">
<h2 class="fl tac">
<span class="c-333">主讲课程</span>
</h2>
<section class="c-tab-title">
<a href="javascript: void(0)"> </a>
</section>
</header>
<!-- 无数据提示 开始-->
<!-- /无数据提示 结束-->
<!-- 课程列表 开始-->
<!-- /课程列表 结束-->
</div>
</section>
</section>
<!-- /讲师介绍 结束 -->
</div>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 2、讲师详情显示
<!-- 讲师基本信息 开始 -->
<section class="fl t-infor-box c-desc-content">
<div class="mt20 ml20">
<section class="t-infor-pic">
<img :src="teacher.avatar" :alt="teacher.name">
</section>
<h3 class="hLh30">
<span class="fsize24 c-333">{{ teacher.name }}
{{ teacher.level===1?'高级讲师':'首席讲师' }}
</span>
</h3>
<section class="mt10">
<span class="t-tag-bg">{{ teacher.intro }}</span>
</section>
<section class="t-infor-txt">
<p class="mt20">{{ teacher.career }}</p>
</section>
<div class="clear"/>
</div>
</section>
<!-- /讲师基本信息 结束 -->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 3、无数据提示
<!-- 无数据提示 开始-->
<section class="no-data-wrap" v-if="courseList.total==0">
<em class="icon30 no-data-ico"> </em>
<span class="c-666 fsize14 ml10 vam">没有相关数据,小编正在努力整理中...</span>
</section>
<!-- /无数据提示 结束-->
1
2
3
4
5
6
2
3
4
5
6
# 4、当前讲师课程列表
<!-- 课程列表 开始-->
<article class="comm-course-list">
<ul class="of">
<li v-for="course in courseList" :key="course.id">
<div class="cc-l-wrap">
<section class="course-img">
<img :src="course.cover" class="img-responsive">
<div class="cc-mask">
<a :href="'/course/'+course.id" title="开始学习" target="_blank" class="comm-btn c-btn-1">开始学习</a>
</div>
</section>
<h3 class="hLh30 txtOf mt10">
<a
:href="'/course/'+course.id"
:title="course.title"
target="_blank"
class="course-title fsize18 c-333">{{ course.title }}</a>
</h3>
</div>
</li>
</ul>
<div class="clear"/>
</article>
<!-- /课程列表 结束-->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 5、测试
编辑 (opens new window)
上次更新: 2024/06/15, 15:12:25