繁体   English   中英

Spring 通过多值属性查询存储库

[英]Spring Repository query by multi-valued property

试图解决我有 class 学生的问题。

public class Student {
    @Id
    UUID id;
    String name;
    Long year;
    List<Attribute> attributes;
}

还有一个 class 属性

public class Attribute {
    @Id
    private UUID id;
    private String field;
    private String value;
}

现在我想按年份和属性列表进行搜索。

public interface StudentRepository extends PagingAndSortingRepository<Student, UUID> {
    Page<Student> findStudentByYearAndAttributesIn(Long year, List<Attribute> attributes, Pageable pageable);
}

一种可能的搜索是查找 2000 年以来所有拥有棕色或金色头发或棕色或蓝色眼睛的学生。

{
  "hair" : ["brown","blonde"],
  "eyes" : ["brown","blue"]
}

当我尝试运行这个项目时出现错误

Error creating bean with name 'studentRepository' defined in com.example.StudentRepository defined in @EnableJdbcRepositories declared on Application: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Cannot query by multi-valued property: attributes; nested exception is java.lang.IllegalArgumentException: Cannot query by multi-valued property: attributes

我如何查询这个多值属性

您必须在@Query注释中定义自定义查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM