Playframework 为什么render()和render(“some template.html”)的行为不同

Playframework 为什么render()和render(“some template.html”)的行为不同,playframework,render,playframework-1.x,Playframework,Render,Playframework 1.x,我刚开始学习公司要求的Play 1.x,在本部分中,我通过Play教程创建了一个博客引擎: 为什么他们建议以字符串renderApplication/show.html形式提供模板名称,post;在验证错误的情况下?为什么不运行showpost.postId控制器,看起来也是这样 似乎只有当作为renderApplication/show.html、post执行时,模板才会捕获验证错误;如果作为showpost.postId执行,则验证错误对模板不可见 验证错误发生在postComment方法中

我刚开始学习公司要求的Play 1.x,在本部分中,我通过Play教程创建了一个博客引擎:

为什么他们建议以字符串renderApplication/show.html形式提供模板名称,post;在验证错误的情况下?为什么不运行showpost.postId控制器,看起来也是这样


似乎只有当作为renderApplication/show.html、post执行时,模板才会捕获验证错误;如果作为showpost.postId执行,则验证错误对模板不可见

验证错误发生在postComment方法中。调用showpost.postId有效地触发HTTP重定向,因此验证错误将丢失,因为服务器是无状态的

public static void show(Long id) {
    Post post = Post.findById(id);
    render(post);
}

public static void postComment(Long postId, @Required String author, @Required String content) {
    Post post = Post.findById(postId);
    if (validation.hasErrors()) {
        render("Application/show.html", post); // why not show(post.postId) ?
    }
    post.addComment(author, content);
    show(postId);
}