Spring Data JPA: Query by Example?

前端 未结 3 1922
渐次进展
渐次进展 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 20:52

    This is now possible with Spring Data. Check out http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example

    Person person = new Person();                         
    person.setLastname("Smith");                          
    Example example = Example.of(person);
    List results = personRepository.findAll(example);
    

    Note that this requires very recent 2016 versions

        
            org.springframework.data
            spring-data-jpa
            1.10.1.RELEASE       
        
        
            org.springframework.data
            spring-data-commons
            1.12.1.RELEASE
        
    

    see https://github.com/paulvi/com.example.spring.findbyexample

提交回复
热议问题