名师列表和详情接口

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);
}
相关推荐
青云计划7 小时前
知光项目知文发布模块
java·后端·spring·mybatis
赶路人儿7 小时前
Jsoniter(java版本)使用介绍
java·开发语言
Victor3567 小时前
MongoDB(9)什么是MongoDB的副本集(Replica Set)?
后端
Victor3567 小时前
MongoDB(8)什么是聚合(Aggregation)?
后端
探路者继续奋斗7 小时前
IDD意图驱动开发之意图规格说明书
java·规格说明书·开发规范·意图驱动开发·idd
消失的旧时光-19438 小时前
第十九课:为什么要引入消息队列?——异步系统设计思想
java·开发语言
yeyeye1118 小时前
Spring Cloud Data Flow 简介
后端·spring·spring cloud
A懿轩A8 小时前
【Java 基础编程】Java 面向对象入门:类与对象、构造器、this 关键字,小白也能写 OOP
java·开发语言
Tony Bai9 小时前
告别 Flaky Tests:Go 官方拟引入 testing/nettest,重塑内存网络测试标准
开发语言·网络·后端·golang·php
乐观勇敢坚强的老彭9 小时前
c++寒假营day03
java·开发语言·c++