简体   繁体   English

Apache Velocity多个变量

[英]Apache velocity multiple variables

I am using apache velocity to generate multiple templates, the problem is that in each templates multiple (read many) variables are being used and it becomes very tedious to initialize each and every variable seperately. 我正在使用apache velocity生成多个模板,问题是在每个模板中使用了多个(读很多)变量,并且分别初始化每个变量变得非常乏味。

Is there a work around this or i have no other option? 有没有解决的办法,或者我没有其他选择?

See there are two work around this thing, the 1st and the best option is that you create a Java Bean class that will contain all your template variables and you can then just initialise separate objects for each and every instance of your template, you just have merge the object with context. 看到有两种解决方法,第一个和最好的选择是创建一个Java Bean类,该类将包含所有模板变量,然后可以为模板的每个实例初始化单独的对象,将对象与上下文合并。

Another way is creating and using a java property file which is not only tedious as you have to create separate property file for each and every time you want to create a new file from your template but also deprecated. 另一种方法是创建和使用Java属性文件,这不仅繁琐,因为您每次要从模板创建新文件时都必须分别创建单独的属性文件,但不推荐使用。

You can read about this more on Apache velocity official documentation. 您可以在Apache Velocity官方文档中了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM