Use example methods of the QueryByExampleExecutor <T> interface in Spring JPA data

What are the application methods of this interface QueryByExampleExecutor<T>in Spring JPA data. I searched Google and found nothing but official documentation.

Perhaps someone can tell me the correct resource with examples.

In particular, is there an findAll(Example<S> example, Pagable pageable)easier way for this interface to search , paginate, and sort?

+4
source share
2 answers

From Spring Docs to Example:

(QBE). . ExampleMatcher.

, QueryByExampleExecutor Spring Query By Example.

:

Query by Example (QBE) - . . IBM Research 1970- SQL. , , , .

, #findAll, , :

<S extends T> Page<S> findAll(Example<S> example, Pageable pageable)
a Page , Example. , Page.

, QBE , SQL, Spring Data API, .

+2

Spring Data JPA query-by-example Example ExampleMatcher . . , :

Person.java

public class Person {

  @Id
  private String id;
  private String firstname;
  private String lastname;
  private Address address;

  // … getters and setters omitted
}

PersonResource.java

@RestController
@RequestMapping("/api")
public class PersonResource {

@GetMapping("/persons/{name}")
@Timed
public ResponseEntity<List<Person>> getPersons(@ApiParam Pageable pageable, @PathVariable String  name) {
    log.debug("REST request to get Person by : {}", name);
    Person person = new Person();                         
    person.setFirstname(name);  
    Page<Person> page = personRepository.findAll(Example.of(person), pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/persons");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
+1

Source: https://habr.com/ru/post/1656542/


All Articles