名师列表和详情接口

1、 名师的列表接口(分页的列表查询)

在service_edu模块com/atguigu/eduservice/api目录下创建TeacherApiController实现前台讲师展示功能。

java 复制代码
package com.atguigu.eduservice.api;
import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description="前台讲师展示")
@RestController
@RequestMapping("/eduservice/teacherapi")
@CrossOrigin
public class TeacherApiController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "前台讲师分页查询")
    @GetMapping("getFrontTeacherList/{current}/{limit}")
    public R getFrontTeacherList(@PathVariable Long current, @PathVariable Long limit){
        Page<EduTeacher> pageParam = new Page<>(current,limit);
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create");
        teacherService.page(pageParam,wrapper);
        List<EduTeacher> records = pageParam.getRecords();
        long currentPage = pageParam.getCurrent();
        long pages = pageParam.getPages();
        long size = pageParam.getSize();
        long total = pageParam.getTotal();
        boolean hasNext = pageParam.hasNext();
        boolean hasPrevious = pageParam.hasPrevious();
        //把分页数据存入map
        Map<String,Object> map = new HashMap<>();
        map.put("items", records);
        map.put("current", currentPage);
        map.put("pages", pages);
        map.put("size", size);
        map.put("total", total);
        map.put("hasNext", hasNext);
        map.put("hasPrevious", hasPrevious);

        return R.ok().data(map);
    }

}

2、根据id查询讲师详情方法实现

在com/atguigu/eduservice/api目录下TeacherApiController中创建根据id查询讲师详情的方法。

java 复制代码
@ApiOperation(value = "根据id查询讲师详情")
@GetMapping("getTeacherInfo/{id}")
public R getTeacherInfo(@PathVariable String id){
    //1 查询讲师基本信息
    EduTeacher eduTeacher = teacherService.getById(id);
    //2 讲师所讲课程信息
    QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
    wrapper.eq("teacher_id",id);
    List<EduCourse> courseList = courseService.list(wrapper);
    return R.ok().data("eduTeacher",eduTeacher).data("courseList",courseList);
}
相关推荐
one year.1 分钟前
Linux:线程同步与互斥
java·开发语言
一 乐4 分钟前
旅游|内蒙古景点旅游|基于Springboot+Vue的内蒙古景点旅游管理系统设计与实现(源码+数据库+文档)
开发语言·前端·数据库·vue.js·spring boot·后端·旅游
JaguarJack7 分钟前
15 个 Eloquent 高级技巧,瞬间提升你的 Laravel 应用性能
后端·php·laravel
YDS82911 分钟前
苍穹外卖 —— Spring Cache和购物车功能开发
java·spring boot·后端·spring·mybatis
苍老流年11 分钟前
1. SpringBoot初始化器ApplicationContextInitializer使用与源码分析
java·spring boot·后端
星光一影12 分钟前
基于SpringBoot智慧社区系统/乡村振兴系统/大数据与人工智能平台
大数据·spring boot·后端·mysql·elasticsearch·vue
劲墨难解苍生苦12 分钟前
spring ai alibaba mcp 开发demo
java·人工智能
leonardee12 分钟前
Spring 中的 @ExceptionHandler 注解详解与应用
java·后端
不爱编程的小九九13 分钟前
小九源码-springboot103-踏雪阁民宿订购平台
java·开发语言·spring boot
Elieal14 分钟前
Spring 框架核心技术全解析
java·spring·sqlserver