3

我有一个 SpringBoot 2 应用程序,它使用 Couchbase 作为数据库、Spring-Boot 和 Spring-Data 以及 Lombok 的 getter 和 equals 方法我已经创建了这个存储库

@ViewIndexed(designDoc = "bendicionesDoc")
public interface BenRepository extends CouchbaseRepository<BendicionesDoc, String> {

    @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY uuid IN data.identifier.id SATISFIES uuid = $1 END")
    List<BendicionesDoc<Item>> findById(String id);


}

这里是使用 Lombok 库创建的所有对象

public class BendicionesDoc<T>implements Serializable {


        @Field
        private T data;

    }

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
public class Item {

    private List<Identifier> identifier;


}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
public class Identifier {

    private String id;
    private MasterServant idContext;
    private MasterServant idScope;

}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class MasterServant {

    private String context;
    @JsonValue
    @EqualsAndHashCode.Include
    private String value;

    private Name valueDescription;

    @JsonCreator
    public MasterServant(String value) {
        this.value = value;
    }

}

但是当我运行存储库查询时,我总是得到 0 个结果,即使有文档。在数据库中:

4

1 回答 1

0

You need to define your reference type in CouchbaseRepository<T, K> then simply add the reference type Item as CouchbaseRepository<BendicionesDoc<Item>, String> and just use Repository query keywords for findById(String id).

public interface BenRepository extends CouchbaseRepository<BendicionesDoc<Item>, String> { 

    List<BendicionesDoc<Item>> findById(String id);

}
于 2019-10-23T16:44:53.917 回答