Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Apache Velocity中的Bug或隐藏功能_Java_Templates_Velocity - Fatal编程技术网

Java Apache Velocity中的Bug或隐藏功能

Java Apache Velocity中的Bug或隐藏功能,java,templates,velocity,Java,Templates,Velocity,我使用ApacheVelocity1.7生成Perl代码。还有一种典型的Perl语法,用于按键($map{key})访问散列中的值,这使得Velocity变得疯狂。下面是显示我的问题的代码: String template = "#$language hash usage example:\n" + "my $value = $map{key};"; Map<String, Object> context = new HashMap<St

我使用ApacheVelocity1.7生成Perl代码。还有一种典型的Perl语法,用于按键(
$map{key}
)访问散列中的值,这使得Velocity变得疯狂。下面是显示我的问题的代码:

    String template = "#$language hash usage example:\n" +
            "my $value = $map{key};";
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("language", "Perl");
    VelocityContext cntx = new VelocityContext(context);
    StringWriter output = new StringWriter();
    Velocity.evaluate(cntx, output, "Template1", template);
    System.out.println(output.toString());

我试图在文档中找到有关这种行为的信息,但失败了。有人知道那里发生了什么吗?

这肯定是个bug。我在代码库中修复了它,但在等待下一个版本(可能需要一定的时间)时,以下模板将保持perl模板文件的可维护性并避免错误:

 my $value = $map{ key };

只有前面的空格是必要的,第二个空格是为了美观。

你看到了吗?你看,perl模板文件可能很大,如果我理解正确的话,我必须用
${esc.d}
替换所有的美元,对吗?在这样的操作之后,很难维护此模板。或者你是说别的?不过,我更愿意先了解这个问题。
 my $value = $map{ key };