MVel 2.0.15 doc
MVEL is an expression language – similar to OGNL – and a templating engine. I’d like to give you an example of MVEL Templates in this post so you can find out if MVEL might work for you. Templating Examples This is how templating with MVEL looks like. Basic Object Access <h1>@{name}</h1> Simple Iteration <p>@foreach{index : alphabetical}<a href="@{index.uri}">@{index.description}</a>@end{}</p> Accessing Static Methods <a href="@{ua.pageURI}">@{org.apache.commons.lang.StringEscapeUtils.escapeHtml(ua.name)}</a> Inline Ternary Operator <li>@{ua.hitsTotal} total @{ua.hitsTotal == 1 ? "Hit" : "Hits"}.</li> MVEL Integration The following code integrates MVEL into your application. The first part parses a template from a String, the second part applies an object to the template and writes it to a file. public class MVELTemplateWriter { private final CompiledTemplate template; /** * Constructor for MVELTemplateWriter. * * @param template the MVEL template */ public MVELTemplateWriter(String template) { super(); this.template = TemplateCompiler.compileTemplate(template); } /** * Merge an Object with the template and write the output * tof. * * @param o the Object * @param f the output File */ public void write(Object o, File f) throws IOException { String output= (String) TemplateRuntime.execute(template, o); Writer writer= null; try { if (!f.getParentFile().exists()) { boolean created= f.getParentFile().mkdirs(); assert created; } writer= new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); writer.write(output); } finally { close(writer); } }} You use this code like you would use other templating engines/expression languages: You add your objects to a Map and then merge the Map with a template. In the template, you reference the objects in the Map by their key. Note that the template is pre-compiled for performance reasons. You can use something like FileUtils.readFileToString(File) to read a template file into a String.
- 宏势2014-09-10还可以,参考一下!
- 粉丝: 1
- 资源: 3
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab开发的全面详解LTE:MATLAB建模、仿真与实现-simulink.rar
- 自动驾驶定位系列教程二:系统架构.pdf
- 整站程序8优技巧网-8ujq.rar
- 世界各个国家或地区国际域名缩写
- 基于matlab开发的根据rvm回归模型自己编的matlab程序.rar
- 基于matlab开发的该程序为国内一所大学编写的LTE链路层仿真程序,根据LTE标准协议编写的,很容易看懂.rar
- 高效C++学生成绩管理系统:教育技术+C++17编程+数据管理+教务自动化
- 搜索链接要广告分类系统 v2.0-yad20.rar
- 基于matlab开发的Tipping的相关向量机RVM的回归MATLAB程序,有英文注释,可以运行.rar
- 一个点击正反转程序实例,可实现案件电机正反转