培训学校课程管理系统-计算机毕设Java|springboot实战项目

时间:2025-03-23 16:35:33
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import your.package.name.model.Course; import your.package.name.service.CourseService; import java.util.List; @RestController @RequestMapping("/courses") public class CourseController { @Autowired private CourseService courseService; // 获取课程列表 @GetMapping public List<Course> listCourses() { return courseService.list(); } // 分页获取课程列表 @GetMapping("/page") public Page<Course> listCoursesWithPage( @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) { return courseService.page(new Page<>(current, size)); } // 根据条件查询课程 @GetMapping("/search") public List<Course> searchCourses(Course course) { QueryWrapper<Course> queryWrapper = new QueryWrapper<>(); queryWrapper .eq(StringUtils.isNotBlank(course.getName()), "name", course.getName()) .eq(course.getTeacherId() != null, "teacher_id", course.getTeacherId()); return courseService.list(queryWrapper); } // 添加课程 @PostMapping public boolean addCourse(@RequestBody Course course) { return courseService.save(course); } // 更新课程信息 @PutMapping("/{id}") public boolean updateCourse(@PathVariable Integer id, @RequestBody Course course) { course.setId(id); return courseService.updateById(course); } // 删除课程 @DeleteMapping("/{id}") public boolean deleteCourse(@PathVariable Integer id) { return courseService.removeById(id); } }

相关文章