【问题标题】:@Query Annotation in Spring Cassandra Repository not workingSpring Cassandra 存储库中的 @Query 注释不起作用
【发布时间】:2021-09-18 18:07:41
【问题描述】:

我正在尝试在 Java Springboot 中将 @Query 参数用于 Cassandra 存储库。

但它不起作用。下面是示例代码。

@Repository
public interface Table1Repository extends CassandraRepository<Table1,TransactionKey>{

    @Query("SELECT * FROM table1 WHERE code=?0 and product=?1 and id=?2 order by transactiontime DESC limit ?3")
    List<Table1> searchTransactionLimit(String code,String product,Double id, int limit);
    
}

如果我在@Query 中硬编码 id 的值,那么它就可以工作了。 例如,

@Query("SELECT * FROM table1 WHERE code=?0 and product=?1 and id=17.0 order by transactiontime DESC limit ?3")

所以基本上,类型 String 和 int 在 @Query 中工作。但是 Double 类型不起作用。

【问题讨论】:

    标签: spring spring-boot cassandra spring-data-jpa


    【解决方案1】:

    您也可以尝试如下,但该限制数需要在方法名称中。

    List<Table1> findTop10ByCodeAndProductAndIdOrderByTransactiontimeDesc(String code,String product,Double id);
    

    您也可以通过 pageable 尝试以下操作。

    Pageable pages = PageRequest.of(0, limit);
    
    findByCodeAndProductAndIdOrderByTransactiontimeDesc(String code,String product,Double id,Pageable pages  );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 2014-08-14
      • 2022-12-04
      • 2019-03-25
      • 1970-01-01
      • 2013-12-28
      • 2018-08-27
      相关资源
      最近更新 更多