diff --git a/README.md b/README.md index 0b254b8..f3406a7 100644 --- a/README.md +++ b/README.md @@ -156,78 +156,3 @@ System.out.println(unknown); at ch.obermuhlner.scriptengine.example.ScriptEngineExample.runErrorExample(ScriptEngineExample.java:84) at ch.obermuhlner.scriptengine.example.ScriptEngineExample.main(ScriptEngineExample.java:14) ``` - -# Spring Expression Language - -The Spring Expression Language (SpEL) is a powerful expression language that supports querying and manipulating an object graph at runtime. - -Refer to the [4.2.x Spring Documentation](https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/expressions.html) -for details. - -The following example shows how to execute a simple SpEL script with variables: -```java -try { - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("spel"); - - engine.put("inputA", 2); - engine.put("inputB", 3); - engine.put("output", 0); - - String script = "" + - "#output = #inputA + #inputB"; - - Object result = engine.eval(script); - System.out.println("Result: " + result); - - Object output = engine.get("output"); - System.out.println("Output Variable: " + output); -} catch (ScriptException e) { - e.printStackTrace(); -} -``` - -The console output shows that the `output` variable was modified by the script: -```console -Result: 5 -Output Variable: 5 -``` - -Since SpEL has the concept of a root object that is passed into expression -the `SpringExpressionScriptEngine` provides a special variable `ROOT`. - -```java -public class Person { - public String name; - public int birthYear; - - @Override - public String toString() { - return "Person{name=" + name + ", birthYear=" + birthYear + "}"; - } -} -``` - -```java -try { - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("spel"); - - Person person = new Person(); - person.name = "Eric"; - person.birthYear = 1967; - engine.put(SpringExpressionScriptEngine.ROOT, person); - - String script = "" + - "name+birthYear"; - - Object result = engine.eval(script); - System.out.println("Result: " + result); -} catch (ScriptException e) { - e.printStackTrace(); -} -``` - -```console -Result: Eric1967 -```