Condition
节点主要依据上游节点的执行状态(成功、失败)执行对应分支。Switch
节点主要依据全局变量的值和用户所编写的表达式判断结果执行对应分支
${setValue(key=value)}
,如下图,自定义输出参数(out)-isExist
,选择类型boolean
及其默认值(value)- false
,也可以不填写,在脚本内容中通过逻辑判断使用 ${setValue(isExist=true)}
给 isExist
赋值.size()
方法,此时只能改上游任务,比如select count(id) from ...
int
比较大小是可以的,shell节点定义Boolean
,比较时候却要加引号Boolean
方法,即大小相等比较engine.eval()
转换,计算类可以指定Double
,比较结果可以指定Boolean
等测试类
import java.util.List;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class Test {
private static ScriptEngineManager manager;
private static ScriptEngine engine;
static {
manager = new ScriptEngineManager();
engine = manager.getEngineByName("js");
// Get the list of all available engines
List<ScriptEngineFactory> list = manager.getEngineFactories();
// Print the details of each engine
for (ScriptEngineFactory f : list) {
System.out.println("Engine Name:" + f.getEngineName());
System.out.println("Engine Version:" + f.getEngineVersion());
System.out.println("Language Name:" + f.getLanguageName());
System.out.println("Language Version:" + f.getLanguageVersion());
System.out.println("Engine Short Names:" + f.getNames());
System.out.println("Mime Types:" + f.getMimeTypes());
}
}
public static boolean evaluateB(String expression) throws ScriptException {
Object result = engine.eval(expression);
return (Boolean) result;
}
public static Integer evaluateI(String expression) throws ScriptException {
Object result = engine.eval(expression);
return (Integer) result;
}
public static void main(String[] args) throws ScriptException {
System.out.println(evaluateB("6> 5"));
System.out.println(evaluateI("6 + 5"));
System.out.println(evaluateI("if(5==6) { 5+6 } else { 5*6 } "));
}
}
执行结果
Engine Name:Oracle Nashorn
Engine Version:1.8.0_151
Language Name:ECMAScript
Language Version:ECMA - 262 Edition 5.1
Engine Short Names:[nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript]
Mime Types:[application/javascript, application/ecmascript, text/javascript, text/ecmascript]
true
11
30
id=6