Using Spring Data JPA can I do a query by example where a particular entity instance is used as the search criteria?
For example (no pun intended), if I have a Person
entity that looks like:
@Entity
public class Person {
private String firstName;
private String lastName;
private boolean employed;
private LocalDate dob;
...
}
I could find all employed persons with a last name of Smith born on January 1, 1977 with an example:
Person example = new Person();
example.setEmployed(true);
example.setLastName("Smith");
example.setDob(LocalDate.of(1977, Month.JANUARY, 1));
List<Person> foundPersons = personRepository.findByExample(example);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…