当文件名以 r 开头时,速度模板无法正确渲染
我知道这是迷信,但我发现当模板文件名以 r、t 等字符开头时,我的模板无法正确呈现。当名称以 i、a 等开头时,相同的模板可以正确呈现。
该模板应该为对象集合的每个对象生成一个 java 类。每次必须渲染模板时,我都会传递对象的名称。文件名替换为对象的名称,可以正常工作。但是类名(与上面的文件名相同)未正确呈现。
有人见过这样的东西吗?是否存在不应成为模板名称一部分的关键字?
I know this is superstitious, but I see that my template is not rendered correctly when template filename begins with characters such as r,t. The same template renders correctly when the name starts with i, a etc.
This template should generate one java class per object for a collection of objects. I'm passing the name of the object each time it has to render the template. The file name has a substitution with the name of the object, which works correctly. But the classname(which is the same as the above filename) is not rendered correctly.
Has anyone seen something like this? Are there keywords that should not be part of a template name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,模板名称只是一个字符串,除非您有一些邪恶的自定义资源加载器喜欢扰乱您的头脑。
哦,不,我从来没有听说过这样的事情,即使在使用和研究 Velocity 的十年里也是如此。我想我可以有把握地说这是第一次。 :)
No, the template name is just a string, unless you have some evil custom resource loader that likes to mess with your head.
Oh, and no, i've never heard of such a thing, even in a decade of using and working on Velocity. I think i can safely say this is a first. :)
过了很长一段时间,我重新审视了这个问题,结果发现这是我的代码中的一个错误。作为渲染特定模板时我的操作之一的副作用,contextObject 被重置。它与模板名称无关。
为什么 r 和 t 失败是因为副作用发生在名称以 q 开头的模板中。模板是按字母顺序挑选的。
所以现在一切都很好。而且速度确实非常好!
After a long time, I revisited this and it turns out that it was a bug in my code. As a side effect of one of my actions while rendering a particular template, the contextObject was reset. It had nothing to do with the template name.
Why it failed for r and t is because the side effect occurred in a template whose name started with q. And the templates were picked in alphabetical order.
So all is good now. And velocity is indeed excellent!