简体   繁体   English

如何以编程方式解决Apache速度变量?

[英]How programmatically resolve apache velocity variable?

Velocity documentation tells that to resolve a variablev a #set derective or POJO with corresponding property should be used. 速度文档告诉您 ,要解析变量v,应使用具有相应属性的#set指示或POJO。 Is there a way to provide a custome resolver? 有没有办法提供客户解析器? Eg when $client appears in template, resolver go to database, retrieve Client entity, get name field and fill $client place holder. 例如,当$client出现在模板中时,解析器go数据库,检索Client实体,获取name字段并填写$client占位符。 Does velocity template engine support such extensions? 速度模板引擎是否支持此类扩展?

You may try with the ReferenceInsertionHandler, but its purpose is rather to filter (aka modify, alter in some way) displayed values than to fetch values from Velocity references. 您可以尝试使用ReferenceInsertionHandler,但其目的是过滤 (也称为以某种方式修改,更改)显示的值,而不是从Velocity引用中获取值。

Such a task would typically be done by the context objects themselves. 这样的任务通常将由上下文对象本身完成。 That is, $client can contain an object which knows how to fetch and return the client's name on its toString() method. 也就是说, $client可以包含一个对象,该对象知道如何在其toString()方法上获取并返回客户端的名称。

You can also use objects with getters and setters, so that you can write $client.name as long as $client.address . 您还可以将对象与getter和setter一起使用,以便您可以将$client.name写入,只要$client.address You'll get yourself doing some kind of ORM . 您将自己做某种ORM As a side note, there are existing libraries easing this task for Velocity. 附带说明一下, 现有的库简化了Velocity的这项任务。

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

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