0

我试试这个并且工作正常。

@Autowired

private CassandraOperations cassandraOperations;

in my method
{
  String cqlAll = "select * from customer where cust_id=123";

  List<Customer> results = cassandraOperations.select(cqlAll, Customer.class);  
  for (Customer p : results) 
  {
    System.out.println(p.getCust_id() + "-"+p.getCust_name()+"-"+p.getCust_password());
  }
}

但我想将值传递给字符串,以便我可以单独编写查询文件。像这样的东西,

String cqlAll = "select * from customer where cust_id=?";

objects[] obj = {123};

List<Customer> results = cassandraOperations.select(cqlAll, obj ,Customer.class);

for (Customer p : results) 
{
System.out.println(p.getCust_id() + "-"+p.getCust_name()+"-"+
  p.getCust_password());
}
4

1 回答 1

0

CassandraOperationselect 方法也可以构建com.datastax.driver.core.querybuilder.Select,正如我从spring data cassandra 文档中看到的那样。

我对spring data cassandra没有太多经验,因为我们直接使用datastax java驱动程序,但这应该适用于select

final Select select = QueryBuilder.select().all().from("customer")
            .where(QueryBuilder.eq("cust_id", 123)).limit(200);
cassandraOperations.select(select ,Customer.class);

123可以是从对象中提取的任何动态值。

可以使用 CqlOperations 进行更新:

CqlOperations cqlOperations = new CqlOperations(); //or autowire it
final Statement update = QueryBuilder.update("customer")
                .with(QueryBuilder.set("email", "example@example.com"))
                .where(QueryBuilder.eq("cust_id", 123));
cqlOperations.execute(update);

QueryBuilder可以在此处找到更多示例。

于 2015-07-08T06:54:42.060 回答