package com.example.service; import com.example.entity.StudentCourse; import com.example.exception.CustomException; import com.example.mapper.StudentCourseMapper; import com.example.mapper.StudentMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; @Service public class StudentCourseService { @Resource StudentCourseMapper studentCourseMapper; public void add(StudentCourse studentCourse) { StudentCourse course = studentCourseMapper.selectByCondition(studentCourse);//通过学生Id和课程ID筛选看这个学生是否选过这门课 if (course != null) { throw new CustomException("您已选过这门课程"); } studentCourseMapper.insert(studentCourse); } public PageInfo selectPage(Integer pageNum, Integer pageSize,StudentCourse studentCourse) { PageHelper.startPage(pageNum,pageSize); List list = studentCourseMapper.selectAll(studentCourse); return PageInfo.of(list); } public void deleteById(Integer id) { studentCourseMapper.deleteById(id); } }