我想使用Java EL来解析表达式。表达式可以是String,Integer,Float等。 以下是我为ElResolver设置上下文的地图
$ git checkout -b <branch> --track <remote>/<branch>
我想迭代遍历地图的每个元素,并从hashmap
获取相应键的值Map<String,String> varibalesMap= new HashMap<String,String>();
varibalesMap.put("var1","1000");
varibalesMap.put("var2","DemoTest");
varibalesMap.put("var3","3000$ 10 %");
if(null!=dynamicVaribalesMap && !dynamicVaribalesMap.isEmpty())
{
ELContext elContext = JRFContext.getELContext();
ELResolver elResolver = elContext.getELResolver();
elResolver.setValue(elContext, null, "varibalesMap", varibalesMap);
}
String result1=getValuesMap(varibalesMap.get("var1");
String result2=getValuesMap(varibalesMap.get("var2");
String result3=getValuesMap(varibalesMap.get("var3");
虽然我能够看到填充的对象
variableExpression
可变
(String)variableExpression.getValue(ElContext.getELContext());是 为String返回null。
public String getValuesMap(String result)
{
ExpressionFactory expressionFactory = ElContext.getExpressionFactory();
ELContext elContext = ElContext.getELContext();
ELResolver elResolver = elContext.getELResolver();
Map<String,String> dynVar=null;
String returnValue="";
if(elContext!=null && elContext.isPropertyResolved())
{
dynamicVariables=(Map<String, String>) elResolver.getValue(elContext, null, "varibalesMap");
if(null!=dynVar&& !dynVar.isEmpty())
{
ValueExpression variableExpression = expressionFactory.createValueExpression(ElContext.getELContext(), "#{" + dynVar.get(result) + "}", String.class);
returnValue = (String) variableExpression.getValue(ElContext.getELContext());
}
}
return returnValue;
}