tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Spring > Expression Language > Root Variable

Root Variable 

The Spring Expression Language (SpEL) is a simple and powerful expression language which helps to query and manipulate objects at runtime. The following example shows accessing evaluation context root variable.

File Name  :  
com/bethecoder/tutorials/spring3/tests/spel/RootVariableTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.spring3.tests.spel;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

import com.bethecoder.tutorials.spring3.basic.Employee;

public class RootVariableTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    StandardEvaluationContext stdContext = 
      new StandardEvaluationContext(new Employee(1"ABC"9999));
    
    ExpressionParser parser = new SpelExpressionParser();
    Employee emp = parser.parseExpression("#root").getValue(stdContext, Employee.class);
    System.out.println(emp);
    
    String name = parser.parseExpression("#root.name").getValue(stdContext, String.class);
    System.out.println(name);
  }

}
   

It gives the following output,
Employee[1, ABC, 9999.0]
ABC


                    Print

   



Books Recommendation

 
 
bl  br