我在spring-data-couchbase,中使用couchbase3,并且希望使用多列的spring数据存储库来查询数据。
public interface UserAccountRepository extends CrudRepository<UserAccount, Long> {
public UserAccount findByEmail(Query eMail);
public UserAccount findByEmailAndStatus(Query query); // fn with multiple column, but not getting the result
}我应该如何为相同的映射函数和约简函数编写?
为了使函数findByEmail(查询eMail);工作,我使用Map ()添加了视图
function (doc, meta) {
emit(doc.email,doc);
}此视图以电子邮件为键,值为文档。但是如果我需要使用电子邮件和状态来查询呢?景色应该是怎样的?
我见过这种联系,但不太清楚。https://stackoverflow.com/questions/28938755
发布于 2015-08-18 07:58:33
我能够使springdata数据函数调用复合键视图。我的文档名是: Data 复合键视图
function (doc, meta) {
if(doc && doc._class == "com.couchbase.entity.Data"){
emit([doc.key1, doc.key2], doc);
}
}SpringData存储库Infer面如下所示:
package com.couchbase.repository;
import java.util.List;
import org.springframework.data.couchbase.core.view.View;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.entity.Data;
public interface DataRepository extends CrudRepository<Data, String> {
@View(designDocument="Data",viewName="findByKey1AndKey2")
public List<Data> findByKey1AndKey2(Query query);
}测试类如下所示:
import com.couchbase.client.protocol.views.ComplexKey;
import com.couchbase.client.protocol.views.Query;
public class DataTest extends WebAppConfigurationAware{
@Autowired
private DataRepository dataRepository;
@Test
public void testStringDataCompoundQuery(){
Object[] objArr = new Object[2];
objArr[0] = "aaa";
objArr[1] = 1;
Query query = new Query();
query.setKey(ComplexKey.of(objArr));
System.out.println(dataRepository.findByKey1AndKey2(query));
}
}如果这对你有用,请投票。
发布于 2015-07-01 10:17:34
您可以使用复合键,如文档中的描述:http://docs.couchbase.com/developer/dev-guide-3.0/compound-keys.html
https://stackoverflow.com/questions/31116690
复制相似问题