1. 程式人生 > >bboss oreach循環嵌套遍歷map

bboss oreach循環嵌套遍歷map

reac cin java int try print parse param ava


foreach循環嵌套遍歷map
foreach嵌套dsl腳本定義

<property name="dynamicInnerDsl">
<![CDATA[{ ## 最多返回1000條記錄
size: #[size],
"query": {
"bool": {
"must": [
#set($needComma = false)
#foreach($condition in $conditions.entrySet())
#foreach($item in $condition.value.entrySet())
#if($needComma), #else #set($needComma = true) #end
{
"$condition.key": {
"$item.key": #[conditions[$condition.key][$item.key],serialJson=true]
}
}
#end
#end
]
}
}
}]]>
</property>
傳遞參數和解析上述dsl的java方法代碼

@Test
public void dynamicInnerDsl(){
Map conditions = new HashMap<String,Map<String,Object>>();
Map<String,Object> term = new HashMap<String, Object>();
term.put("terma","tavalue");
term.put("termb","tbvalue");
term.put("termc","tcvalue");
conditions.put("term",term);

Map params = new HashMap();
params.put("conditions",conditions);
params.put("size",1000);
//加載配置文件中的dsl信息,解析dsl語句dynamicInnerDsl
ESUtil esUtil = ESUtil.getInstance("esmapper/dsl.xml");
String parseResult = ESTemplateHelper.evalTemplate(esUtil,"dynamicInnerDsl",params);
//打印解析結果
System.out.println(parseResult);

}
運行上述代碼打印出來的實際dsl

{
"size": 1000,
"query": {
"bool": {
"must": [

{
"term": {
"termb": "tbvalue"
}
},
{
"term": {
"termc": "tcvalue"
}
},
{
"term": {
"terma": "tavalue"
}
}
]
}
}
}

bboss oreach循環嵌套遍歷map