Home  >  Spring Core

Language Reference in Spring Expression (SpEL)

By Arvind Rai, October 06, 2013
In this page we will see many examples representing expression. In our example we have used Literal expressions, Inline lists, Methods etc.

Literal expressions in Spring Expression Language

package com.concretepage;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class SpELTest {
	public static void main(String[] args) {
		ExpressionParser parser = new SpelExpressionParser();
		boolean falseVal = (Boolean) parser.parseExpression("false").getValue();
		System.out.println(falseVal);
		Object nullVal = parser.parseExpression("null").getValue();	
		System.out.println(nullVal);
	}
}
 

Inline Lists in Spring Expression Language

package com.concretepage;
import java.util.List;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class SpELTest {
	public static void main(String[] args) {
		ExpressionParser parser = new SpelExpressionParser();
		List<Integer> list =  (List<Integer>) parser.parseExpression("{1,2,3,4}").getValue();
		for(Integer i: list){
			System.out.println(i);
		}
	}
}
 

Using Java Methods with Spring Expression Language

package com.concretepage;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class SpELTest {
	public static void main(String[] args) {
		ExpressionParser parser = new SpelExpressionParser();
		String str = (String)parser.parseExpression("'Hello World!'.substring(1, 3)").getValue();
		System.out.println(str);
	}
}
 
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS


©2019 concretepage.com | Privacy Policy | Contact Us