CourseDAO.java 816 B

1234567891011121314151617181920212223242526
  1. package nju.seec.helper.dao;
  2. import nju.seec.helper.entity.Course;
  3. import nju.seec.helper.util.enums.ExceptionType;
  4. import nju.seec.helper.util.exception.HelperException;
  5. import org.springframework.data.jpa.repository.JpaRepository;
  6. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  7. import org.springframework.stereotype.Repository;
  8. /**
  9. * @author cst
  10. */
  11. @Repository
  12. public interface CourseDAO extends JpaRepository<Course, Long>, JpaSpecificationExecutor<Course> {
  13. /**
  14. * 封装findById
  15. *
  16. * @param id
  17. * @return
  18. */
  19. default Course findCourseById(Long id) {
  20. return this.findById(id)
  21. .filter(course -> course.getDeleteAt() == 0)
  22. .orElseThrow(() -> HelperException.of(ExceptionType.NOT_FOUND, "找不到课程"));
  23. }
  24. }