Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

SPEL的helloWorld

$
0
0
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));  //求值,根据上下文获得表达式
		}
}

作者:howlaa 发表于2013-1-11 15:35:51 原文链接
阅读:0 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>