我有一個包含字串串列的物體。我想用另一個串列在該串列中搜索,例如:我想要所有具有指定標簽串列的主題。所以基本上,我希望我提供的字串串列包含在每個物體都有的字串串列中。看起來很簡單,但我產生了一個錯誤。
主題物體:
public class Topic {
// ...
@ElementCollection
@Column(name = "tags")
private List<String> tags;
// ...
}
在存盤庫中查詢:
@Query("select t from Topic t where t.tags in (:tags)")
List<Topic> findAllByTags(@Param("tags") List<String> tags);
測驗:
@Test
void findAllByTags() {
List<String> tags = new ArrayList<>(Arrays.asList("web", "mobile"));
List<Topic> allByTags = topicService.findAllByTags(tags);
}
例外:
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [web] did not match expected type [java.util.Collection (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [web] did not match expected type [java.util.Collection (n/a)]
uj5u.com熱心網友回復:
你必須加入標簽:
@Query("select t from Topic t join t.tags tags where tags in (:tags)")
List<Topic> findAllByTags(@Param("tags") List<String> tags);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/371992.html
上一篇:Angular12:如果單擊第一個按鈕,按鈕樣式將不起作用
下一篇:MultiThread,ApartmentState.MTA點例外:System.PlatformNotSupportedException:此平臺不支持COMInterop
