Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Spring Data JPA example matcher with additional conditions

I am trying to use the Example of Spring JPA to do the search. With the following code, most of it fits the requirements.

public Page<Shop> findShops(Shop condition, Pageable pageable) {
        ExampleMatcher matcher = ExampleMatcher.matching().withStringMatcher(StringMatcher.CONTAINING).withIgnoreCase();
        return shopDao.findAll(Example.of(condition, matcher), pageable);
    }

In addition, I ONLY need the SHOP with status NOT equals DELETED. Something like, .withMatcher("status", notEqual()) or maybe .withMatcher("status", contains()) a list.

I am not sure if and how Example Matcher could do such thing. Could anybody help me with this?

like image 820
shan.lu Avatar asked Sep 28 '16 08:09

shan.lu


1 Answers

For the one WHERE clause you dont need QBE. Query from method should be enough:

Page<Shop> findByStatusNot(String status, Pageable page);

http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation

like image 76
Robert Niestroj Avatar answered Oct 17 '22 23:10

Robert Niestroj