I have a java spring app. It does back end stuff, offering a Restful API, all using an Oracle database.
For most resources, it follows a typical design pattern: "Controller > Service > Repository > DB".
At the repository level, when extending the JpaRepository interface, one can define a set of methods without having to provide a body, just like this:
public interface SurgeryRepository extends JpaRepository<Surgery, String> {
public List<Surgery> findByPracticeNameContainingIgnoreCase(String substring);
public Surgery findById(String id);
}
What i would like to know is how to define a method that allow me to retrieve multiple rows using a list of ids, something like:
public List<Surgery> findByIDs(List<String> IDs);
Something that should automatically map to this sort of SQL
SELECT * FROM SURGERIES WHERE SURGERY_ID IN ('101',102,103',104',105',106')
... but without having to write a native query in the java code. (and not necessarily for id, it could be for any field) Thanks in advance.
You can use:
findAll(Iterable<ID> ids)
Method provided by JpaRepository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With