I want to write a FindAll() method which returns a List of all Student objects. But the CRUDRepository only has Iterable<> findAll().
The goal is to get all students in a List and pass it to the API Controller so I can get all the students with a http GET.
What would be the best way to convert this method to List<> FindAll()
In my current code the findAll method in the StudentService gives me the Incompatible types found: Iterable. Required: List error.
Service
@Service
@RequiredArgsConstructor
public class StudentServiceImpl implements StudentService {
@Autowired
private final StudentRepository studentRepository;
//Incompatible types found: Iterable. Required: List
public List<Student> findAll() {
return studentRepository.findAll();
}
}
API Controller
@RestController
@RequestMapping("/api/v1/students")
public class StudentAPIController {
private final StudentRepository studentRepository;
public StudentAPIController(StudentRepository studentRepository) {
this.studentRepository = studentRepository;
}
@GetMapping
public ResponseEntity<List<Student>> findAll() {
return ResponseEntity.ok(StudentServiceImpl.findAll());
}
}
StudentRepository
public interface StudentRepository extends CrudRepository<Student, Long> {
}