for example, if I pass in a string ${value1==value2}
, how can I use java to parse the meaning of value1
and value2
and get the calculation result, or how to identify the parameters value1
and value2
in this statement?
now I already know that using ScriptEngine
, you can add the values of value1
and value2
to the value1==value2
formula according to the js syntax, but you still need to know the parameter name in the expression to replace
the requirement now is that after a series of operations, the values of several variables have been saved in a Map, and then you need to read a string s
to parse and extract the variable values needed by s
from Map to calculate, like this
valuesMap.put("value1", value1);
valuesMap.put("value2", value2);
...
String s = "value1==value2";
ScriptEngine engine = ...
//TODO svalueList
engine.put(valueList,get(i), valuesMap.get(valueList,get(i)));
how to solve the step of fetching the parameter list? Or what should I do to achieve this whole function?