IBM Cloudant NoSql:为 "fields" 创建 QueryBuilder 变量

IBM Cloudant NoSql: create QueryBuilder variable for "fields"

对于 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);

我希望它们成为变量,而不是对字段进行硬编码。我管理除 "fields".

之外的所有变量
        // 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);

如何将 "fields" 设为变量?

在这里找到答案: https://github.com/cloudant/java-cloudant/blob/master/cloudant-client/src/main/java/com/cloudant/client/api/query/QueryBuilder.java

现在的代码是:

    // 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);