名师列表和详情接口

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);
}
相关推荐
之歆5 小时前
Spring AI入门到实战到原理源码-MCP
java·人工智能·spring
yangminlei5 小时前
Spring Boot3集成LiteFlow!轻松实现业务流程编排
java·spring boot·后端
qq_318121595 小时前
互联网大厂Java面试故事:从Spring Boot到微服务架构的技术挑战与解答
java·spring boot·redis·spring cloud·微服务·面试·内容社区
计算机毕设VX:Fegn08955 小时前
计算机毕业设计|基于springboot + vue医院设备管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
J_liaty5 小时前
Spring Boot整合Nacos:从入门到精通
java·spring boot·后端·nacos
面汤放盐6 小时前
后端系统设计文档模板
后端
阿蒙Amon6 小时前
C#每日面试题-Array和ArrayList的区别
java·开发语言·c#
daidaidaiyu6 小时前
Spring IOC 源码学习 一文学习完整的加载流程
java·spring
2***d8857 小时前
SpringBoot 集成 Activiti 7 工作流引擎
java·spring boot·后端
五阿哥永琪7 小时前
Spring中的定时任务怎么用?
java·后端·spring