我有一个SpringBoot 2应用程序,该应用程序使用Couchbase作为数据库,使用Spring-Boot和Spring-Data,以及Lombok的getters和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个结果。在数据库中:
reference type
中定义您的CouchbaseRepository<T, K>
,然后只需将引用类型Item
添加为CouchbaseRepository<BendicionesDoc<Item>, String>
,并且只需将Repository query keywords用作findById(String id)
。