package com.fangzhu.spel;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
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;
import com.fangzhu.dao.UserDao;
import com.fangzhu.model.User;
public class SpElTest extends TestCase{
public void testSpEl1() {
//ExpressionParser接口用来解析一个表达式字符串。
//在这个例子中,表达式串是一个被单引号包括标注的字符串。
//Expression接口用来求前面定义的表达式串的值。
//当调用parser.parseExpression和exp.getValue时分别可能抛出ParseException和EvaluationException异常。
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("'Hello,World!'");
System.out.println((String) exp.getValue());
exp = parser.parseExpression(" 'Hello'.concat(' World!')"); // 这里调用了字符串String的concat方法
System.out.println((String) exp.getValue());
exp=parser.parseExpression("new String('hello,world!').toUpperCase()");
System.out.println((String) exp.getValue());
}
public void testSpEl2() {
// EvaluationContext接口用来求一个解析属性,方法,域的表达式值以及帮助类型转换。
//其即插即用实现StandardEvaluationContext使用反射机制来操作对象。
//为获得好的性能缓存java.lang.reflect的Method,Field和Constructor实例。
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
UserDao userDao = context.getBean("userDao", UserDao.class);
User user = userDao.find("25");
EvaluationContext ec = new StandardEvaluationContext(user);
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("name");
System.out.println((String)exp.getValue(ec));
System.out.println((String)exp.getValue(user));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
spring3使用示例 (158个子文件)
UserDaoImpl.class 3KB
SpElTest.class 2KB
OtherIntroduction.class 2KB
TopicController.class 2KB
SpringDaoTest.class 2KB
Spring3DaoTest.class 2KB
UserDaoImp.class 2KB
HelloWorldAction.class 2KB
HelloWorldClient.class 1KB
UserController.class 1KB
UserDaoImp$UserRowMapper.class 1KB
AroundAdvice.class 1KB
User.class 1KB
TestAdvice.class 1KB
BuyBookImpl.class 1KB
HelloWorldStr.class 1KB
UserDaoImp$1.class 1KB
AfterAdvice.class 1KB
BeforeAdvice.class 1KB
Users.class 951B
ThrowAdvice.class 702B
NoThisBookException.class 578B
BuyBookException.class 569B
HelloWorld.class 530B
BuyBook.class 244B
UserDao.class 220B
BackBook.class 177B
.classpath 1KB
.classpath 1KB
.classpath 845B
.classpath 786B
.classpath 593B
org.eclipse.wst.common.component 430B
org.eclipse.wst.common.component 426B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
aspectjweaver-1.6.6.jar 1.53MB
ojdbc14.jar 1.12MB
org.springframework.context-3.0.0.RELEASE.jar 642KB
org.springframework.context-3.0.0.RELEASE.jar 642KB
org.springframework.context-3.0.0.RELEASE.jar 642KB
org.springframework.context-3.0.0.RELEASE.jar 642KB
org.springframework.context-3.0.2.RELEASE.jar 642KB
org.springframework.beans-3.0.0.RELEASE.jar 539KB
org.springframework.beans-3.0.0.RELEASE.jar 539KB
org.springframework.beans-3.0.0.RELEASE.jar 539KB
org.springframework.beans-3.0.0.RELEASE.jar 539KB
org.springframework.beans-3.0.2.RELEASE.jar 537KB
org.springframework.web.servlet-3.0.2.RELEASE.jar 394KB
standard.jar 384KB
org.springframework.web.servlet-3.0.0.RELEASE.jar 378KB
org.springframework.web-3.0.2.RELEASE.jar 374KB
org.springframework.jdbc-3.0.0.RELEASE.jar 373KB
org.springframework.jdbc-3.0.2.RELEASE.jar 369KB
org.springframework.core-3.0.0.RELEASE.jar 351KB
org.springframework.core-3.0.0.RELEASE.jar 351KB
org.springframework.core-3.0.0.RELEASE.jar 351KB
org.springframework.core-3.0.0.RELEASE.jar 351KB
org.springframework.web-3.0.0.RELEASE.jar 351KB
org.springframework.core-3.0.2.RELEASE.jar 350KB
org.springframework.orm-3.0.2.RELEASE.jar 325KB
org.springframework.aop-3.0.0.RELEASE.jar 317KB
cglib-nodep-2.1.jar 316KB
org.springframework.aop-3.0.2.RELEASE.jar 313KB
org.springframework.transaction-3.0.0.RELEASE.jar 226KB
org.springframework.transaction-3.0.2.RELEASE.jar 226KB
org.springframework.test-3.0.0.RELEASE.jar 202KB
org.springframework.test-3.0.2.RELEASE.jar 200KB
org.springframework.jms-3.0.2.RELEASE.jar 179KB
org.springframework.web.portlet-3.0.2.RELEASE.jar 169KB
org.springframework.expression-3.0.2.RELEASE.jar 153KB
org.springframework.expression-3.0.0.RELEASE.jar 151KB
org.springframework.expression-3.0.0.RELEASE.jar 151KB
org.springframework.expression-3.0.0.RELEASE.jar 151KB
org.springframework.expression-3.0.0.RELEASE.jar 151KB
aspectjrt-1.6.6.jar 113KB
org.springframework.context.support-3.0.2.RELEASE.jar 98KB
servlet-api.jar 95KB
servlet-api.jar 95KB
org.springframework.oxm-3.0.2.RELEASE.jar 59KB
org.springframework.asm-3.0.2.RELEASE.jar 52KB
org.springframework.asm-3.0.0.RELEASE.jar 52KB
org.springframework.asm-3.0.0.RELEASE.jar 52KB
org.springframework.asm-3.0.0.RELEASE.jar 52KB
org.springframework.asm-3.0.0.RELEASE.jar 52KB
commons-logging.jar 37KB
commons-logging.jar 37KB
commons-logging.jar 37KB
commons-logging.jar 37KB
commons-logging-1.0.4.jar 37KB
org.springframework.web.struts-3.0.2.RELEASE.jar 31KB
org.springframework.aspects-3.0.0.RELEASE.jar 30KB
org.springframework.aspects-3.0.2.RELEASE.jar 29KB
jstl.jar 20KB
org.springframework.instrument.tomcat-3.0.2.RELEASE.jar 5KB
aopalliance.jar 4KB
org.springframework.instrument-3.0.2.RELEASE.jar 2KB
SpElTest.java 2KB
UserDaoImpl.java 2KB
UserDaoImp.java 1KB
共 158 条
- 1
- 2
资源评论
- Mainsun2014-03-14可以直接使用,非常好。
- kang86902012-07-09spring3的一些例子,包含aop,dao,rest,mvc等 java project,可直接使用
fangzhu19880123
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功