Variables and
Constructors in SpEL:-
Variables can be referenced in the expression using the syntax #variableName.
Variables are set using the method setVariable on the
StandardEvaluationContext.
Employee emp = new Employee("Vipul Sharma", "Proff");
StandardEvaluationContext context = new StandardEvaluationContext(emp);
context.setVariable("newName", "Rahul Sharma");
parser.parseExpression("Name = #newName").getValue(context);
System.out.println(emp.getName()) // "Rahul Sharma"
Constructors:
Constructors can be invoked using the new operator.
Employee emp = p.parseExpression(
"new org.spring.samples.spel.emp.Employee('Vipul Sharma', 'India')")
.getValue(Employee.class);
//create new emp instance within add method of List
p.parseExpression(
"Members.add(new org.spring.samples.spel.emp.Employee(
'Vipul Sharma', 'India'))").getValue(societyContext);