parent
a761a27e80
commit
efbea2975f
1 changed files with 54 additions and 0 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("删除成功!!"); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue