Home  >  Spring Core

TemplateParserContext in Spring Expression Language (SpEL)

By Arvind Rai, October 27, 2013
TemplateParserContext is used to evaluate expressing templating of literal text. # is used to start expression. In our example we are using random method for Expression templating. Find the example below.

SpELTest.java
package com.concretepage;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.common.TemplateParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class SpELTest {
	public static void main(String[] args) {
		ExpressionParser parser = new SpelExpressionParser();
		String randomNum = parser.parseExpression("random number : #{T(java.lang.Math).random()}", 
	                          new TemplateParserContext()).getValue(String.class);
		
		System.out.println(randomNum);
		
	}
}
 
Output
random number : 0.9180394702760882
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us