`

MVEL2.0模板(模板集成)

阅读更多

MVEL 2.0 Template Integration

Using MVEL templates is straight-forward and easy. Like regular MVEL expressions, they can be executed interpretively, or be pre-compiled and be re-used for faster evaluation.

The org.mvel.templates.TemplateRuntime Class

The TemplateRuntime class is the center of the template engine. You can pass a template to be evaluated to the template engine by way of the eval() method.

In general, the template engine follows all the same rules for context and variable binding, with an overloaded set of eval() methods.

Here's a simple example of parsing a template interpretively:

String template = "Hello, my name is @{name.toUpperCase()}");
Map vars = new HashMap();
vars.put("name", "Michael");

String output = (String) TemplateRuntime.eval(template, vars);

At the end of execution, the "output" variable will contain the string:

Hello, my name is MICHAEL

The org.mvel.templates.TemplateCompiler Class

The TemplateCompiler class allows for pre-compilation of the templates.

When you compile a template, a compact, reusable evaluation tree is produced that can be quickly used to evaluate a template. It is used straightforwardly:

String template = "1 + 1 = @{1+1}";

// compile the template
CompiledTemplate compiled = TemplateCompiler.compileTemplate(template);

// execute the template
String output = (String) TemplateRuntime.execute(compiled);

At the end of execution, the "output" variable will contain the string:

1 + 1 = 2
分享到:
评论

相关推荐

    mvel2.0语法指南.pdf

    ### MVEL 2.0 语法指南精要 #### 一、引言 MVEL (Micro Velocity) 是一种高效、灵活且易于使用的表达式语言,主要用于处理数据和执行计算任务。MVEL 2.0 版本在继承 Java 语法的基础上进行了大量优化,以提高性能...

    MVEL 2.0表达式语言

    - 更好的Java集成:可能增强了与Java代码的互操作性,如更容易地将MVEL表达式嵌入到Java代码中。 通过提供的`mvel`文件,可能包含了MVEL 2.0的API文档、示例代码、测试用例或库的源码。这些资源可以帮助你深入了解...

    mvel2-2.0.18

    功能强大的基于Java应用程序的表达式语言.

    MVEL 2.doc

    下面将详细介绍MVEL 2.0的使用方法、核心概念以及如何与应用程序集成。 ### MVEL表达式基础 MVEL表达式的例子如`foo.name == "Mr. Foo"`,这个表达式检查`foo.name`的值是否等于字符串"Mr. Foo"。这里的`foo`可以...

    mvel-maven-plugin:MVEL 模板 maven 插件

    mvel-maven-插件 使用 MVEL 渲染模板的 Maven 插件。 用法 < groupId>uk.co.codezen < artifactId>mvel-maven-plugin < version>1.0 < goal>render < template

    \\(^_^)/ 表达式解析器(MVEL)

    MVEL与Java的集成 - **MVEL编译器**: 将MVEL表达式编译为Java字节码,提高执行效率。 - **API接口**: 提供了`MVEL.executeExpression()`方法,接受一个表达式字符串并返回执行结果。 - **类和对象的访问**: MVEL...

    MVel 2.0.15 doc

    MVEL是一种表达式语言,与OGNL类似,同时也是一个模板引擎。它的主要功能是提供简洁的语法来访问对象属性、执行循环和条件判断,以及进行字符串格式化等。MVEL模板允许开发者以一种声明式的方式将动态数据嵌入到静态...

    Activiti BPMN2.0设计器eclipse插件

    Eclipse是广受欢迎的Java集成开发环境(Integrated Development Environment, IDE),而“Activiti BPMN2.0设计器eclipse插件”则是为了让开发者在Eclipse中更方便地设计和编辑BPMN 2.0流程图的工具。 此插件适用于...

    mvel 2.0.15

    Getting Started for 2.0 MVEL is very easy to use, and just as easy to integrate into your application. Let's take a quick look at a simple MVEL expression: foo.name == "Mr. Foo" This simple ...

    mvel14-1.2.21.jar

    mvel14-1.2.21.jar mvel14-1.2.21.jar

    MVEL脚本语言语法

    很好的MVEL基础语法学习资料,希望能帮到你~

    mvel2-2.3.0.Final.jar

    java运行依赖jar包

    mvel2-2.1.6.Final-javadoc.jar

    mvel2-2.1.6.Final-javadoc

    easyrulesplusmvel:一个结合 Easy Rules 和 MVEL 的 Java 项目

    通过查看源码,我们可以学习如何在实际项目中集成 Easy Rules 和 MVEL,理解它们的交互方式,以及如何定义和执行业务规则。 使用 Easy Rules 和 MVEL 的好处在于,它们可以帮助开发者将业务逻辑从核心应用程序代码...

    StarUML text-template example

    模板语言通常基于某种模板引擎,如MVEL或FreeMarker,这些引擎允许用户在模板中嵌入变量和逻辑表达式。在"template.cot"文件中,我们可以找到用这种模板语言编写的代码,这些代码将被StarUML解析并用于生成目标文本...

Global site tag (gtag.js) - Google Analytics