此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Data Redis 3.5.3spring-doc.cadn.net.cn

modules/ROOT/pages/redis/redis-repositories/query-by-example.adoc 中未解析的 include 指令 - include::4@data-commons::p age$query-by-example.adoc[]spring-doc.cadn.net.cn

运行示例

以下示例对存储库使用“按示例查询”:spring-doc.cadn.net.cn

示例 1.使用存储库按示例查询
interface PersonRepository extends ListQueryByExampleExecutor<Person> {
}

class PersonService {

  @Autowired PersonRepository personRepository;

  List<Person> findPeople(Person probe) {
    return personRepository.findAll(Example.of(probe));
  }
}

Redis 存储库及其二级索引支持 Spring Data 的 Query by Example 功能的子集。 特别是,仅使用精确值、区分大小写和非空值来构造查询。spring-doc.cadn.net.cn

二级索引使用基于集合的作(设置交集、设置并集)来确定匹配的键。将未编制索引的属性添加到查询中不会返回任何结果,因为不存在索引。“按示例查询”支持检查索引配置,以仅在查询中包含索引涵盖的属性。这是为了防止意外包含非索引属性。spring-doc.cadn.net.cn

不区分大小写的查询和不受支持StringMatcher实例在运行时被拒绝。spring-doc.cadn.net.cn

以下列表显示了支持的“按示例查询”选项:spring-doc.cadn.net.cn

以下列表显示了按示例查询不支持的属性:spring-doc.cadn.net.cn