[英]Java Project - Velocity Not replacing certain strings
I am loading up a vm tgemplate with velocity and chnaging some of the parameters I have around 10 parameters that can change in my template 我正在用速度加载vm tgemplate并更改一些参数,我有大约10个可以在模板中更改的参数
For the following portion of my template 对于我模板的以下部分
window.location = "$html5Dirhtml5/index.html?page=$pageNumber"
I get this output 我得到这个输出
window.location = "$html5Dirhtml5/index.html?page=1"
Any idea why velocity is not converting the html5Dir attribute but it is setting the page? 知道为什么速度不转换html5Dir属性而是设置页面吗?
The attributes definitely exist in the attributes passed to velocity, I have checked this My velocity code is as follows 这些属性肯定存在于传递给速度的属性中,我已经检查了一下我的速度代码如下
public static StringWriter generateTextFromTemplate(String templateFile, Map<String, String> params) {
LOG.debug("Entered generateTextFromTemplate - templateFile:{}", templateFile);
StringWriter writer = null;
try {
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityEngine.init();
VelocityContext velocityContext = new VelocityContext();
for (Map.Entry<String, String> entry : params.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
velocityContext.put(key, value);
LOG.error("key:{}, value:{}", key, value);
}
// get the Template
Template template = velocityEngine.getTemplate(templateFile);
// now render the template into a Writer
writer = new StringWriter();
template.merge( velocityContext, writer );
} catch (Exception e) {
LOG.error("{}", e);
writer = null;
}
return writer;
}
First of all, check that there is an actual html5Dirhtml5 parameter. 首先,检查是否有实际的html5Dirhtml5参数。 If that isn't the parameter you want and it's html5Dir, then you need to use the form ${html5Dir} in the template to demarcate what the actual name is.
如果这不是您想要的参数,而是html5Dir,那么您需要在模板中使用$ {html5Dir}形式来划分实际名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.