我正在尝试使用 IN 子句和 Spring Data 中的 @Query 注释查询 Cassandra 表。我有一个表,其分区键为 last_name,集群键为 first_name。
我有这个查询工作
@Query("SELECT * FROM people WHERE last_name=?0")
public List<People> findByLastName(String lastName);
我想做类似的事情
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN ?1")
public List<People> findByLastName(String lastName, String[] firstName);
我让它使用
CassandraOperations.select("SELECT * FROM people WHERE last_name=" + lastName +
" AND first_name IN (" + concatinatedNameList + ")", People.class);
但出于多种原因(代码风格、测试,我发誓还有更多)我更喜欢使用@Query。有任何想法吗?
编辑更多信息!
传入数组、集合或列表返回Caused by: java.lang.IllegalArgumentException: encountered unsupported query parameter type [class [Ljava.lang.String;] in method public abstract
也试过:
String firstName = "Joe,Jim";
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN (?1)")
public List<People> findByLastName(String lastName, String firstName);
没有找到,图书馆搜索具有连接名称的单个人('Joe,Jim')
String firstName = "'Joe','Jim'";
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN (?1)")
public List<People> findByLastName(String lastName, String firstName);
没有找到,请求被转义并结束('''Joe'',''Jim''')
String firstName = "Joe','Jim"; // Hoping the library would just add the outer quotes, getting desperate
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN (?1)")
public List<People> findByLastName(String lastName, String firstName);
没有找到,请求被转义并结束('Joe'',''Jim')