一般,一個接口會調用業務邏輯層的一個方法,來實現該接口的具體業務邏輯和功能。
- 業務邏輯層需要編寫接口
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);
}
}