如何使用具有附加条件的Spring Data JPA示例匹配器

sha*_*.lu 7 java jpa spring-data-jpa

我正在尝试使用Spring JPA的示例来进行搜索.使用以下代码,大部分代码符合要求.

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

另外,我只需要状态NOT等于DELETED的SHOP.类似的东西,.withMatcher("status", notEqual()) 或者可能 .withMatcher("status", contains())是列表.

我不确定示例匹配器是否以及如何做这样的事情.有人可以帮帮我吗?

Rob*_*roj 2

对于第一个WHERE条款,您不需要 QBE。从方法中查询应该足够了:

Page<Shop> findByStatusNot(String status, Pageable page);
Run Code Online (Sandbox Code Playgroud)

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