[英]How to apply like query in JpaRepository on List of String
I am using JpaRepository and I am trying to query into DB using List<String>
so I am using like query for the same and I am not getting any results.我正在使用 JpaRepository 并且我正在尝试使用
List<String>
查询数据库,所以我正在使用类似的查询,但我没有得到任何结果。
Here is my query:这是我的查询:
@Query("SELECT a FROM MappingEntity a WHERE UPPER(a.cuisines) LIKE (% :cuisine_type %) AND ST_distance(ST_POINT(:lng , :lat), a.geoLocation) < :radius")
List<OpentableMappingEntity> getRestaurantsListCuisines1(@Param("cuisine_type") List<String> cuisines, @Param("lat") double latitude, @Param("lng") double longitude, @Param("radius") Integer radius);
@Query("SELECT a FROM MappingEntity a WHERE UPPER(a.cuisines) LIKE CONCAT('%', CONCAT(:cuisine_type, '%')) AND ST_distance(ST_POINT(:lng , :lat), a.geoLocation) < :radius")
List<OpentableMappingEntity> getRestaurantsListCuisines2(@Param("cuisine_type") List<String> cuisines, @Param("lat") double latitude, @Param("lng") double longitude, @Param("radius") Integer radius);
I tried both the query and I am getting an empty response if I remove the like part it will give me the results.我尝试了两个查询,如果我删除类似的部分,我会得到一个空的响应,它会给我结果。
How to apply like query on List?如何在 List 上应用 like 查询?
You can't use LIKE with a list, instead use IN您不能将 LIKE 与列表一起使用,而是使用 IN
Example: a native query with a list:示例:带有列表的本机查询:
SELECT * FROM order AS o WHERE o.fol IN ('OCV3', 'OCV5', 'OPL8');
And a query in the repository:以及存储库中的查询:
@Query(value="SELECT * FROM order AS o WHERE o.fol IN :list", nativeQuery = true)
List<Order> stack(@Param("list") List<String> list);
Both querys show the same results两个查询显示相同的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.