如何通过多个值匹配多个值?(所有匹配)
对于以下示例,提供了标签,查询将返回所有标签匹配的所有文档。如何在 JPA 中做到这一点?谢谢。
数据:
Document 1 : { id: 1, name: "doc1", tags: [1, 2] }
Document 2 : { id: 2, name: "doc2", tags: [2, 3] }
Tag 1 : { id: 1, name: "tag1" }
Tag 2 : { id: 2, name: "tag2" }
Tag 3 : { id: 3, name: "tag3" }
场景:
Criteria: "tag1", "tag2"
=> Return: "doc1"
Criteria: "tag1", "tag2", "tag3"
=> Return: Nothing
Criteria: "tag2"
=> Return: "doc1" and "doc2"
实体:
public class Document {
@Id
private Long id;
@Column
private String name;
@ManyToMany
@JoinTable(name = "DOCUMENT_TAG_RLAT")
private List<Tag> tags;
}
public class Tag {
@Id
private Long id;
@Column
private String name;
}