开发者

Velocity - Delete fields when can't be merged

开发者 https://www.devze.com 2022-12-09 21:13 出处:网络
I use velocity to merge a String(template) with field like hi there I\'am ${name}, And I\'am ${age} old.

I use velocity to merge a String(template) with field like

hi there I'am ${name},
And I'am ${age} old.

velocity merged the field ${name} and ${age} with a kind of hashtable:

velocityEngine.evaluate(context, writer, "", template);

context is the hashtable(or better a VelocityContext 开发者_如何学运维type)

I want when Velocity can't find the field in the context he just delete them.

can i do this with a property or something?


Not sure if it is what you are asking, but if you want to prevent unassigned template vars from showing up in merged templates, you can use quiet notation by writing $!{name}, there is also a global setting for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消