From efbea2975ff3c42cd73265bd5b0cbf2631beb3e3 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 18 Jun 2024 21:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CourseResourceController.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java diff --git a/src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java b/src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java new file mode 100644 index 0000000..af7f8ae --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/courseResource/CourseResourceController.java @@ -0,0 +1,54 @@ +package com.teaching.backend.controller.courseResource; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ResultUtils; + +import com.teaching.backend.model.entity.CourseResources; +import com.teaching.backend.service.impl.CourseResourcesServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("/courses") +public class CourseResourceController { + @Autowired + private CourseResourcesServiceImpl courseResourcesService; + @GetMapping("/all") + public BaseResponse> All(){ + System.out.println("学习记录:"+courseResourcesService.list()); + return ResultUtils.success(courseResourcesService.list()); + } + + @GetMapping("/getall") + public BaseResponse getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, + @RequestParam(value = "pagesize", defaultValue = "10") int pagesize, + String type) { + + List cs = courseResourcesService.getByType(type); + List pageCs = new ArrayList<>(); + //当前页面 + for(int i = (pagenum - 1) * pagesize; i < cs.size() && i < (pagenum) * pagesize; i++){ + pageCs.add(cs.get(i)); + } + long total = cs.size(); // 总记录数 + Page pageInfo = new Page<>(pagenum,pagesize,total); + pageInfo.setRecords(pageCs); + pageInfo.setPages((int)(Math.ceil((double) total / pagesize)));//设置总页数 + return ResultUtils.success(pageInfo); + } + + /** + * 根据id删除 + * @param ids + * @return + */ + @DeleteMapping("/delete") + public BaseResponse deleteRecords(@RequestParam List ids){ + courseResourcesService.removeCourseResources(ids); + return ResultUtils.success("删除成功!!"); + } +}