我正在尝试使用 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);
}
此外,我只需要状态不等于 DELETED 的 SHOP。
比如,.withMatcher("status", notEqual())
或者 .withMatcher("status", contains())
一个列表。
我不确定 Example Matcher 是否以及如何做这样的事情。 有人可以帮我吗?
最佳答案
对于一个 WHERE
子句,您不需要 QBE。来自方法的查询应该足够了:
Page<Shop> findByStatusNot(String status, Pageable page);
http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
关于java - 如何在附加条件下使用 Spring Data JPA 示例匹配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39741744/