commit
2cd9bbe1d7
10 changed files with 115 additions and 14 deletions
@ -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<List<CourseResources>> All(){ |
||||||
|
System.out.println("学习记录:"+courseResourcesService.list()); |
||||||
|
return ResultUtils.success(courseResourcesService.list()); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/getall") |
||||||
|
public BaseResponse<Page> getAll(@RequestParam(value = "pagenum", defaultValue = "1") int pagenum, |
||||||
|
@RequestParam(value = "pagesize", defaultValue = "10") int pagesize, |
||||||
|
String type) { |
||||||
|
|
||||||
|
List<CourseResources> cs = courseResourcesService.getByType(type); |
||||||
|
List<CourseResources> 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<CourseResources> 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<String> deleteRecords(@RequestParam List<Long> ids){ |
||||||
|
courseResourcesService.removeCourseResources(ids); |
||||||
|
return ResultUtils.success("删除成功!!"); |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 138 KiB |
Binary file not shown.
Loading…
Reference in new issue