zoukankan      html  css  js  c++  java
  • Juel Getting Started

    Getting Started

    The JUEL distribution contains the following JAR files:

    1. juel-api-2.2.x.jar - contains the javax.el API classes.
    2. juel-impl-2.2.x.jar
    3. juel-spi-2.2.x.jar 
    1. Factory and Context
      // the ExpressionFactory implementation is de.odysseus.el.ExpressionFactoryImpl
      ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
      
      // package de.odysseus.el.util provides a ready-to-use subclass of ELContext
      de.odysseus.el.util.SimpleContext context = new de.odysseus.el.util.SimpleContext();
    2. Functions and Variables
      // map function math:max(int, int) to java.lang.Math.max(int, int)
      context.setFunction("math", "max", Math.class.getMethod("max", int.class, int.class));
      
      // map variable foo to 0
      context.setVariable("foo", factory.createValueExpression(0, int.class));
    3. Parse and Evaluate
      // parse our expression
      ValueExpression e = factory.createValueExpression(context, "${math:max(foo,bar)}", int.class);
      
      // set value for top-level property "bar" to 1
      factory.createValueExpression(context, "${bar}", int.class).setValue(context, 1);
      
      // get value for our expression
      System.out.println(e.getValue(context)); // --> 1
  • 相关阅读:
    地铁结队开发(一)
    构建之法(一)——软件工程师的成长
    第二周学习总结
    新的开始
    开学第一周作业
    第一周学习总结
    软件工程第六周总结
    软件工程第五周总结
    清明节第三天
    清明节第二天
  • 原文地址:https://www.cnblogs.com/jimboi/p/8137858.html
Copyright © 2011-2022 走看看