Spring Data JPA: Query by Example?

前端 未结 3 1931
渐次进展
渐次进展 2020-12-02 19:59

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

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 21:06

    Spring data relies on top of JPA and EntityManager, not Hibernate and Session, and as such you do not have findByExample out of the box. You can use the spring data automatic query creation and write a method in your repository with the following signature:

    List findByEmployedAndLastNameAndDob(boolean employed, String lastName, LocalDate dob);
    

提交回复
热议问题