SpringBoot之業務邏輯層Service


一般,一個接口會調用業務邏輯層的一個方法,來實現該接口的具體業務邏輯和功能。

  • 業務邏輯層需要編寫接口
public interface StudentService {
    public List<Student> findByClass(Integer classId) throws Exception;
}
  • 接口的實現類
@Service
public class StudentServiceImp implements StudentService {

    @Autowired
    private StudentRepository studentRepository;


    @Override
    public List<Student> findByClass(Integer classId) throws Exception {
        if (classId == null) {
            throw new IllegalArgumentException("Parameter classId can't be null.");  
        }
        return studentRepository.findByClassId(classId);
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM