Juel 表达式使用

JUEL 包的结构例如以下:

 

1.1.1. Juel maven仓库配置

眼下最新的版本号是2.2.7。使用的时候在pom.xml中加入仓库坐标就可以。

<dependency> 
<groupId>de.odysseus.juel</groupId> 
<artifactId>juel-spi</artifactId> 
<version>2.2.7</version> 
</dependency> 
<dependency> 
<groupId>de.odysseus.juel</groupId> 
<artifactId>juel-api</artifactId> 
<version>2.2.7</version> 
</dependency> 
<dependency> 
<groupId>de.odysseus.juel</groupId> 
<artifactId>juel-impl</artifactId> 
<version>2.2.7</version> 
</dependency> 


juel-api-2.2.7.jar ——包括javax.el 包下的一些类

juel-impl-2.2.7.jar ——包括de.odysseus.el 实现类

juel-spi-2.2.7.jar ——包括META-INF/service/javax.el.ExpressionFactory 服务提供资源的定义(假设你的classpath里有多个EL的实现。而你又希望使用JUEL的实现,那么须要调用ExpressionFactory.newInstance() 

1.1.2. Juel hello word

//ExpressionFactory类的实现是de.odysseus.el.ExpressionFactoryImpl  
ExpressionFactory factory = new ExpressionFactoryImpl();  
//de.odysseus.el.util provides包提供即时可用的子类ELContext
//创建上下文对象context
SimpleContext context = new SimpleContext();  
//函数的前缀 函数的名称 ,运行的方法  三个參数的含义
context.setFunction("shareniu", "max", Math.class.getMethod("min", int.class, int.class));
//foo值为3
context.setVariable("foo", factory.createValueExpression(3, int.class));
//解析表达式  
ValueExpression e = factory.createValueExpression(context, "${shareniu:max(foo,bar)}", int.class);  
//设置顶级的属性"bar"值为1  
factory.createValueExpression(context, "${bar}", int.class).setValue(context, 2);
// get value for our expression
System.out.println(e.getValue(context)); // --> 2


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值