@Test public void eval() throws Exception { HashMap<String, Object> params = new HashMap<String, Object>(); params.put("id","0101"); Object eval = DragonGroovyEngine.eval("id.substring(id.length()-4).toLong().intdiv(100)%100",params); System.out.println(eval); params = new HashMap<String, Object>(); params.put("id","1234"); eval = DragonGroovyEngine.eval("id[2..3]",params); System.out.println(eval); }
public static Object eval(String script, Map<String, Object> params) { try { if (params != null) { ScriptContext context = null; context = new SimpleScriptContext(); for (Map.Entry<String, Object> entry : params.entrySet()) { context.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); } return engine.eval(script, context); } return engine.eval(script); } catch (ScriptException e) { throw new DragonShardException("script:" + script + " eval error,params" + params.toString(), e); } }
DragonGroovyEngine { public static Object eval(String script, Map<String, Object> params) { try { if (params != null) { ScriptContext context = null; context = new SimpleScriptContext(); for (Map.Entry<String, Object> entry : params.entrySet()) { context.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); } return engine.eval(script, context); } return engine.eval(script); } catch (ScriptException e) { throw new DragonShardException("script:" + script + " eval error,params" + params.toString(), e); } } }
DragonGroovyEngine { public static Object eval(String script, Map<String, Object> params) { try { if (params != null) { ScriptContext context = null; context = new SimpleScriptContext(); for (Map.Entry<String, Object> entry : params.entrySet()) { context.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); } return engine.eval(script, context); } return engine.eval(script); } catch (ScriptException e) { throw new DragonShardException("script:" + script + " eval error,params" + params.toString(), e); } }  }
DragonGroovyEngine { public static Object eval(String script, Map<String, Object> params) { try { if (params != null) { ScriptContext context = null; context = new SimpleScriptContext(); for (Map.Entry<String, Object> entry : params.entrySet()) { context.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); } return engine.eval(script, context); } return engine.eval(script); } catch (ScriptException e) { throw new DragonShardException("script:" + script + " eval error,params" + params.toString(), e); } }  static Object eval(String script, Map<String, Object> params); }
DragonGroovyEngine { public static Object eval(String script, Map<String, Object> params) { try { if (params != null) { ScriptContext context = null; context = new SimpleScriptContext(); for (Map.Entry<String, Object> entry : params.entrySet()) { context.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); } return engine.eval(script, context); } return engine.eval(script); } catch (ScriptException e) { throw new DragonShardException("script:" + script + " eval error,params" + params.toString(), e); } }  static Object eval(String script, Map<String, Object> params);  }