对于java中的IBM Cloudant NoSql,我可以像这样创建一个QueryBuilder:
QueryBuilder queryBuilder = new QueryBuilder(and(
gt("Movie_year", 1960),
eq("Person_name", "Alec Guinness"))).
sort(Sort.desc("Movie_year")).
fields("Movie_name", "Movie_year").
limit(10);
不要让字段硬编码,而是希望它们是变量。我管理除"字段"。
之外的所有变量 // variables
selector = and(
gt("Movie_year", 1960),
eq("Person_name", "Alec Guinness"));
Sort sort = Sort.desc("Movie_year");
int limit = 10;
int skip = 0;
// create query Builder
queryBuilder = new QueryBuilder(
selector).
sort(sort).
fields("Movie_name", "Movie_year").
limit(limit).
skip(skip);
如何制作"字段"变量?
答案 0 :(得分:0)
代码现在是:
// variables
selector = and(
gt("Movie_year", 1960),
eq("Person_name", "Alec Guinness"));
Sort sort = Sort.desc("Movie_year");
String[] field = {"Movie_name", "Movie_year"};
int limit = 10;
int skip = 0;
// create query Builder
queryBuilder = new QueryBuilder(
selector).
sort(sort).
fields(field).
limit(limit).
skip(skip);