zoukankan      html  css  js  c++  java
  • 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


  • 相关阅读:
    Python基础之只接收关键字参数的函数
    Python基础之可接受任意数量参数的函数
    Django基础之创建admin账号
    GIT版本控制工具
    全站导航
    python中对url编码解码处理
    VUE安装及初始化报错解决办法
    使用Appium+python爬取手机App
    python发送QQ邮件
    docker部署flask项目
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/7291102.html
Copyright © 2011-2022 走看看