spring-boot - 如何在 Spring Boot Cassandra 的 where 子句中使用 IN 运算符

标签 spring-boot cassandra

我正在尝试从 SpringBoot 存储库运行以下查询

@Query("select * from c where id1 =?0 and id2 =?1 and id3 =?2 and c1 =?3 and year in :year and month in :month and day in :day and hour in :hour and minute in :minute"
public List<Counter> findCWithinRangeIn(
    @Param("id1") String id1,
    @Param("id2") String id2,
    @Param("id3") String id3,
    @Param("c1") String c1,
    @Param("year") List<Integer> year,
    @Param("month") List<Integer> month,
    @Param("day") List<Integer> day, 
    @Param("hour") List<Integer> hour,
    @Param("minute") List<Integer> minute);

但总是遇到错误:绑定(bind)变量的数量无效。

请建议如何进一步进行。

注意:我确实关注了 Spring CrudRepository findByInventoryIds(List<Long> inventoryIdList) - equivalent to IN clause但这对我不起作用。

我想执行类似的东西:
select * from c
where id1 ="xyz" and 
      id2 ="abc" and 
      id3 ="pqr" and 
      c1 = "Sample" and
      year IN (2016,2017) and
      month IN (9,10,11) and
      day IN (19,20,24) and
      hour IN (23, 13) and
      minute IN (50, 51, 53)

最佳答案

如果您不需要指定自定义查询,这可能对您有用(基于方法名称)

public List<Counter> findAllById1AndId2AndId3AndC1AndYearInAndMonthInAndDayInAndHourInAndMinuteIn(String id1, STring id2, String id3, String c1, List<Long> years, List<Long> months, List<Long> days, List<Long> hours, List<Long> minutes)

注意:在您的 Counter 实体中,字段名称必须与方法名称中指定的属性名称匹配。

关于spring-boot - 如何在 Spring Boot Cassandra 的 where 子句中使用 IN 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39687574/

相关文章:

spring - org.springframework.web.client.ResourceAccessException : I/O error on GET request for in Microservices

cassandra - Reddit中使用的Cassandra数据库架构是什么?

database - 隐藏在 Cassandra 中的按列数据

java - 在 Solaris (SunOS 5.10 sparc) 上启动 cassandra 失败并出现 SnappyError

Cassandra com.datastax.driver 打开 session 到可能不存在的 key 空间

Linux内存映射文件(已删除)

java - 使用 RestTemplate 和 Jackson 反序列化对 Java 的 JSON 响应

.net - REST API URL 结构建议

使用graphql在spring boot中进行身份验证

java - 如何使用 Spring Boot 在 API Get 方法 Endpoint 中传递多个 id