Spring-mongo-templateにおける埋め込み集合オブジェクトの不定パラメータのクエリー
2155 ワード
テストデータ:
List selectByParas(String[] products,String columnId);
インタフェースの実装:
{
"_id" : ObjectId("54c752ed5c01557fc2eba8f1"),
"title" : " 1,27",
"products" : [{
"name" : " ",
"classid" : "001",
"status" : "1",
"isorg" : "Y",
"_class" : "jyd.info.article.model.Customization"
}],
}
/* 2 */
{
"_id" : ObjectId("54c755f34c2815a1467c5391"),
"title" : " ",
"products" : [{
"name" : "nn ",
"classid" : "001002",
"status" : "1",
"isorg" : "Y",
"_class" : "jyd.info.article.model.Customization"
}, {
"name" : "xx ",
"classid" : "001003",
"status" : "1",
"isorg" : "Y",
"_class" : "jyd.info.article.model.Customization"
}, {
"name" : "ss ",
"classid" : "001",
"status" : "1",
"isorg" : "Y",
"_class" : "jyd.info.article.model.Customization"
}]
}
/* 3 */
{
"_id" : ObjectId("54c758664c28d74b28d8dc67"),
"_class" : "jyd.info.article.model.Article",
"title" : "test3",
"products" : [{
"name" : "eee",
"classid" : "001005",
"status" : "1",
"isorg" : "Y",
"_class" : "jyd.info.article.model.Customization"
}]
}
必要なインタフェース:List selectByParas(String[] products,String columnId);
インタフェースの実装:
@Override
public List selectByParas(String[] products, String columnId) {
Query query = new Query();
Criteria c = new Criteria();
Criteria[] c1 = new Criteria[products.length+1];
for(int i=0;i