velocity

学习-velocity

时光毁灭记忆、已成空白 提交于 2019-12-10 12:20:28
Velocity是什么? Velocity是一个基于java的模板引擎(template engine)。它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象。当Velocity应用于web开发时,界面设计人员可以和java程序开发人员同步开发一个遵循MVC架构的web站点,也就是说,页面设计人 员可以只关注页面的显示效果,而由java程序开发人员关注业务逻辑编码。 Velocity将java代码从web页面中分离出来,这样为web站点的长期维护提供了便利,同时也为我们在JSP和PHP之外又提供了一种可选的方案。 Velocity的能力远不止web站点开发这个领域,例如,它可以从模板(template)产生SQL和PostScript、XML,它也 可以被当作一个独立工具来产生源代码和报告,或者作为其他系统的集成组件使用。Velocity也可以为Turbine web开发架构提供模板服务(template service)。Velocity+Turbine提供一个模板服务的方式允许一个web应用以一个真正的MVC模型进行开发。 1、maven加入依赖 <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId>

How to round off decimal number to 2 places in Velocity template engine?

给你一囗甜甜゛ 提交于 2019-12-10 11:06:22
问题 How can i round off decimal number to 2 places in Velocity Template Engine? #set ($Percentage = $Marks*100/$Total) I want to round off Percentage to 2 decimal places. How can i do that? will Double roundTo(Object decimals, Object num) this work? i.e. will #set ($Percentage = roundTo(2, $Marks*100/$Total)) work? will I have to include anything in .vm file to make this work? 回答1: Use the MathTool from the VelocityTools project. $math.roundTo(2, $value) remember to put the MathTool in your

Velocity与Jsp、Freemarker的对比

感情迁移 提交于 2019-12-10 10:56:31
在java领域,表现层技术主要有三种:jsp、freemarker、velocity。 jsp是大家最熟悉的技术 优点: 1、功能强大,可以写java代码 2、支持jsp标签(jsp tag) 3、支持表达式语言(el) 4、官方标准,用户群广,丰富的第三方jsp标签库 5、性能良好。jsp编译成class文件执行,有很好的性能表现 缺点: jsp没有明显缺点,非要挑点骨头那就是,由于可以编写java代码,如使用不当容易破坏mvc结构。 velocity是较早出现的用于代替jsp的模板语言 优点: 1、不能编写java代码,可以实现严格的mvc分离 2、性能良好,据说比jsp性能还要好些 3、使用表达式语言,据说jsp的表达式语言就是学velocity的 缺点: 1、不是官方标准 2、用户群体和第三方标签库没有jsp多。 3、对jsp标签支持不够好 freemarker 优点: 1、不能编写java代码,可以实现严格的mvc分离 2、性能非常不错 3、对jsp标签支持良好 4、内置大量常用功能,使用非常方便 5、宏定义(类似jsp标签)非常方便 6、使用表达式语言 缺点: 1、不是官方标准 2、用户群体和第三方标签库没有jsp多 性能:velocity应该是最好的,其次是jsp,普通的页面freemarker性能最差,但是在复杂页面上(包含大量判断、日期金额格式化)的页面上

Velocity: How do I define a global variable

北城余情 提交于 2019-12-10 10:48:34
问题 I tried adding a bunch of #set($x=abc) statements in the VM_global_library.vm file, but these variables aren't available in my VM templates. I'd like to set a single global variable for things like the base path to images and such. Is this possible? 回答1: Your VM_global_library.vm should only contain Velocity macros, I suspect any variables declared outside of a macro are just ignored. You could create a separate .vm file that holds all of your globals, and then make sure you #parse it in

How to load a velocity template into an EJB to be used as a mail template

自作多情 提交于 2019-12-10 10:27:43
问题 I have a Java EE 6 application in which I'd like to use velocity to generate mails from a template. I have a @Named bean which is responsible for loading and filling a particular template. The project is a web application, so I placed my templates into WEB-INF/classes (which btw seems to be rather ugly, but I didn't find a more elegant solution by now) and used the ClasspathResourceLoader to access the files. The configuration is as follows: Properties props = new Properties(); props

velocity framework on google app engine

有些话、适合烂在心里 提交于 2019-12-10 05:27:47
问题 i am trying to use velocity framework on google app engine. i wrote a small program with a main method and tried running it locally. i get the following exception : Exception in thread "main" org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.ServletLogChute with the current runtime configuration. at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206) at org.apache.velocity.runtime.log.LogManager

How do I create a custom directive for Apache Velocity

坚强是说给别人听的谎言 提交于 2019-12-10 04:35:42
问题 I am using Apache's Velocity templating engine, and I would like to create a custom Directive. That is, I want to be able to write "#doMyThing()" and have it invoke some java code I wrote in order to generate the text. I know that I can register a custom directive by adding a line userdirective=my.package.here.MyDirectiveName to my velocity.properties file. And I know that I can write such a class by extending the Directive class. What I don't know is how to extend the Directive class -- some

Getting velocity error at statup “VM_global_library.vm”

一个人想着一个人 提交于 2019-12-10 02:39:46
问题 I am using Velocity with Spring. But in Eclipse console I get this error. My code works fine, but I want to know how to fix it. ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader. 回答1: Looks like it is a harmless message. From the Velocity Documentation, if this file is present, Velocity loads this up as a location of global macros. I believe you can override the behaviour by resetting or overriding the value of the below property. velocimacro.library= 回答2

Is there a way to debug Velocity templates in the traditional code debugging sense?

泪湿孤枕 提交于 2019-12-10 02:19:01
问题 We make heavy use of Velocity in our web application. While it is easy to debug the Java side of things and ensure the Velocity Context is populated correctly, it would be extremely valuable to be able to step through the parsing of the VTL on the merge step, set breakpoints, etc. Are there any tools or IDEs/IDE plugins that would make this kind of thing possible with VTL (Velocity Template Language)? 回答1: I had not found any yet. The closest I can get is to hack a logging framework to print

Better way to use Velocity's GenericTools in a Standalone app?

狂风中的少年 提交于 2019-12-09 23:27:14
问题 I want to use VelocityTool's GenericTools for some standard formatting in a standalone app. e.g. have something like this in my Velocity template to use the GenericTools' NumberTool formatter: Total: $numberTool.format("#0.00", $totalPnL) How do I associate the above "$numberTool" with the GenericTool NumberTool. Here's my Velocity code: Velocity.init(); VelocityContext velocityContext = new VelocityContext(); Template template = Velocity.getTemplate("example.vm"); velocityContext.put(