【问题标题】:Why is an incorrect template rendered here?为什么此处呈现不正确的模板?
【发布时间】:2026-01-09 23:15:01
【问题描述】:

我用几个参数调用render(),其中第一个是我作为参数得到的String 参数:

公共静态无效动作(字符串网址){ ...

渲染(网址,...); }

我收到此错误:

The template http://the.contents.of/urlParameter does not exist.

现在,我正在通过render() 进行调试,在那里我看到了这个 sn-p:

protected static void render(Object... args) {
    String templateName = null;
    if (args.length > 0 && args[0] instanceof String && LocalVariablesNamesTracer.getAllLocalVariableNames(args[0]).isEmpty()) {

        // I'm getting into this branch

        templateName = args[0].toString();
    } else {
        templateName = template();
    }
    renderTemplate(templateName, args);
}

if 试图完成什么?为什么我要进入它 - 是因为我没有为 url 使用局部变量吗?这有记录吗?这是什么原理?

我使用的是 1.2.x-c40cf37 版本(在 1.2.4 之后的某个地方)。

【问题讨论】:

    标签: java controller playframework


    【解决方案1】:

    如果您提供一个字符串作为第一个参数,那么它假定它是要呈现的模板的名称。

    例子:

    render("@password", url);
    

    这将呈现密码模板并将 url 变量传递给它。

    在你的情况下,你可以这样做:

    render("@action", url);
    

    编辑:

    您也可以这样做:

    renderArgs.put("url", url);
    render();
    

    希望对你有帮助。

    【讨论】: