我的结构如下。当我使用命令提示符运行查询db.OrganizationAttributeMetaData.find({ "orgid" : 14}).pretty();
时,它返回下面的数据。但是当尝试使用Spring MongoTemplate使用下面的代码获取它时,它返回空白数据对象。调试日志
2017-04-17 13:26:31,661 [http-nio-8080-exec-4] DEBUG o.s.data.mongodb.core.MongoTemplate - 使用查询查找:{" orgid" : 14}字段:{" attrUniqueCode" :1," attributeName" :1," _id" :1, " metadataVersion" :1}用于类:class 集合中的com.debopam.amsapp.model.OrganizationAttributeMetaData: OrganizationAttributeMetaData
方法
@Override
public Page<OrganizationAttributeMetaData> searchOrgMetadata(int orgidentifier,String orgHierachyIdentifier,String serachtext,Pageable page) {
Query query = Query.query(Criteria.where("orgid").is(orgidentifier));
if(StringUtils.hasText(orgHierachyIdentifier)){
List<String> orgHierarchyList = com.debopam.amsapp.util.StringUtils.delimitedStringToConcatenatedStringListReversed(orgidentifier+"", AppConstants.ORG_DELIMITER);
query.addCriteria(Criteria.where(orgHierachyIdentifier).in(orgHierarchyList));
}
if(StringUtils.hasText(serachtext)){
query.addCriteria(Criteria.where("attributeName").regex(Pattern.compile(serachtext, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE))
.orOperator(Criteria.where("attrUniqueCode").regex(Pattern.compile(serachtext, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE))));
}
query.fields().include("attributeName").include("attrUniqueCode").include("id").include("metadataVersion");
//query.with(new Sort(Sort.Direction.ASC, "attrUniqueCode").and(new Sort(Sort.Direction.DESC, "metadataVersion")));
query.with(page);
List<OrganizationAttributeMetaData> orgmetadata = mongoTemplate.find(query, OrganizationAttributeMetaData.class);
long total = mongoTemplate.count(query, OrganizationAttributeMetaData.class);
Page<OrganizationAttributeMetaData> orgMetadataPage = new PageImpl<OrganizationAttributeMetaData>(orgmetadata, page, /*(null == answers)?0:answers.size()*/total);
return orgMetadataPage;
}
数据
{
"_id" : ObjectId("58efd07fb9eb52cb113f21ac"),
"_class" : "com.debopam.amsapp.model.OrganizationAttributeMetaData",
"attributeName" : "ISU",
"attrUniqueCode" : "ISU",
"metadataVersion" : 1,
"htmlAttributes" : {
"0" : {
"isuname" : {
"class" : "com.debopam.amsapp.model.html.HTMLInputTag",
"htmlinputclasstype" : "htmlinputtag",
"serialVersionUID" : NumberLong(1),
"label" : "Name",
"id" : "isuname",
"tagName" : "input",
"inputtype" : "text",
"attributes" : [
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "pattern",
"value" : "",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "readonly",
"value" : "false",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "id",
"value" : "isuname",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "placeholder",
"value" : "ISU Name",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "required",
"value" : "true",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "name",
"value" : "isuname",
"valueRef" : null
}
]
}
},
"1" : {
"lob" : {
"class" : "com.debopam.amsapp.model.html.HTMLInputTag",
"htmlinputclasstype" : "htmlinputtag",
"serialVersionUID" : NumberLong(1),
"label" : "LOB",
"id" : "lob",
"tagName" : "select",
"inputtype" : "select",
"attributes" : [
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "name",
"value" : "lob",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "id",
"value" : "lob",
"valueRef" : null
}
],
"nestedTags" : [
{
"class" : "com.debopam.amsapp.model.html.HTMLOptionTag",
"htmlinputclasstype" : "htmloptiontag",
"serialVersionUID" : NumberLong(1),
"attributes" : [
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "Telecom",
"value" : "Telecom",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "Banking",
"value" : "Banking",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "Media & Entertainment",
"value" : "Media & Entertainment",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "Govt.",
"value" : "Govt.",
"valueRef" : null
},
{
"class" : "com.debopam.amsapp.model.html.HTMLAttribute",
"serialVersionUID" : NumberLong(1),
"name" : "Insurance",
"value" : "Insurance",
"valueRef" : null
}
]
}
]
}
}
},
"orgHierachyIdentifier" : "14",
"orgid" : 14,
"createDate" : ISODate("2017-04-13T19:24:23.535Z"),
"lastModifiedDate" : ISODate("2017-04-13T19:24:23.535Z"),
"createdBy" : "appadmin",
"lastModifiedBy" : "appadmin"
}