Spring JPA Query by Example不返回任何结果

问题描述 投票:2回答:1

我使用Spring的JPA ExampleMatcher但没有成功。

到目前为止,我有:

    ExampleMatcher matcher = ExampleMatcher.matching()
            .withIgnoreNullValues()
            .withMatcher("surname",  match -> match.contains().ignoreCase());
    Person p = new Person();
    v.setSurname("Sm");

希望匹配其Person字段包含指定子字符串的surname对象。

但我一直没有结果。

查找查询日志时,可以看到原因:尝试匹配所有其他字段。

我怎样才能让ExampleMatcher忽略所有其他领域?

java spring spring-data-jpa
1个回答
3
投票

使用.withIgnorePaths()忽略Person中的原始字段。

© www.soinside.com 2019 - 2024. All rights reserved.