String Expression
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 creating a string instance using SpEL.
package com.bethecoder.tutorials.spring3.tests.spel;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class StringExpTest {
/**
* @param args
*/
public static void main ( String [] args ) {
ExpressionParser parser = new SpelExpressionParser () ;
Expression exp = parser.parseExpression ( "'BE THE CODER'" ) ;
String message = ( String ) exp.getValue () ;
System.out.println ( message ) ;
Expression exp2 = parser.parseExpression ( "\"ABCDEFG\"" ) ;
message = exp2.getValue ( String. class ) ;
System.out.println ( message ) ;
}
}
It gives the following output,
BE THE CODER
ABCDEFG