[英]Spring Data (REST) & @Query: optional list as param
我的一個存儲庫中具有以下功能:
@RestResource(path = "filter", rel = "filter")
@Query("SELECT t "
+ "FROM Trip t "
+ "WHERE "
+ "(:from IS NULL OR t.startTs >= :from) "
+ "AND (:categories IS NULL OR t.category IN :categories) ")
Page<Trip> filter(
@Param("from") Instant from,
@Param("categories") List<Category> categories,
Pageable pageable);
Category
是一個枚舉,存儲為:
@Enumerated(EnumType.STRING)
在“ Trips
表中。
當我只用一個類別執行HTTP請求時,我得到正確的結果。 沒有類別鍵的請求時的行為相同。
htt*://localhost/filter?categories=PRIVATE
==>確定
htt*://localhost/filter
==>確定
當使用多個類別時:
htt*://localhost/filter?categories=PRIVATE,BUSINESS
我收到以下異常:
org.hibernate.hql.internal.ast.QuerySyntaxException:意外的AST節點:{vector} [從foo.bar.services.trips.model.Trip t WHERE中選擇count(t)(:from IS NULL或t.startTs> = :from)AND(:categories_0_,:categories_1_是NULL或t.category IN(:categories_0_,:categories_1_))]
有人知道我在做什么錯嗎?
請嘗試以下方法之一:
1)嘗試將涉及列表的語句括在括號中:
@Query("SELECT t "
+ "FROM Trip t "
+ "WHERE "
+ "(:from IS NULL OR t.startTs >= :from) "
+ "AND ((:categories IS NULL) OR (t.category IN :categories)) ")
2)在此處用括號括住:類別
t.category IN (:categories)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.