名师列表和详情接口

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);
}
相关推荐
吾日三省吾码2 小时前
JVM 性能调优
java
Estar.Lee2 小时前
查手机号归属地免费API接口教程
android·网络·后端·网络协议·tcp/ip·oneapi
弗拉唐3 小时前
springBoot,mp,ssm整合案例
java·spring boot·mybatis
oi773 小时前
使用itextpdf进行pdf模版填充中文文本时部分字不显示问题
java·服务器
2401_857610034 小时前
SpringBoot社团管理:安全与维护
spring boot·后端·安全
少说多做3434 小时前
Android 不同情况下使用 runOnUiThread
android·java
知兀4 小时前
Java的方法、基本和引用数据类型
java·笔记·黑马程序员
蓝黑20204 小时前
IntelliJ IDEA常用快捷键
java·ide·intellij-idea
Ysjt | 深4 小时前
C++多线程编程入门教程(优质版)
java·开发语言·jvm·c++