SPEL的helloWorld
[java]
package com.feng.spring.chapter2.helloworld;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
public class HelloTest {
@Test
public void helloWorld(){
ExpressionParser parser = new SpelExpressionParser();//创建解析器
Expression expression = parser.parseExpression("('Hello '+'World').concat(#end)");//解析表达式
EvaluationContext context = new StandardEvaluationContext();//构造上下文
context.setVariable("end", "!");
Assert.assertEquals("Hello World!", expression.getValue(context)); //求值,根据上下文获得表达式
}
}
补充:软件开发 , Java ,