简体   繁体   English

Playframework 2.0中的自动视图路由?

[英]Automatic view routing in playframework 2.0?

All of the examples of view rendering in play documentation I've seen so far required actually specifying a view and then making a render() call. 到目前为止,我看到的播放文档中的所有视图渲染示例都需要实际指定一个视图,然后进行render()调用。

Is there a way to configure a default view for each action and then have the action automatically render the default view specified? 是否可以为每个操作配置默认视图,然后让该操作自动呈现指定的默认视图?

In play 2.0 the templates actually are functions that return instances of the class Html which the Actions then use to create a reply, this means that you must call them to get any output. 在play 2.0中,模板实际上是返回Html类实例的函数,然后Action将其用于创建回复,这意味着必须调用它们才能获取任何输出。

You might be able to create some reflection trixery to achieve what you describe but there is nothing like that built into play. 您可能可以创建一些反射技巧来实现您所描述的内容,但是并没有内置这样的东西。 I personally think that this is one of the really strong points of Play, allowing the compiler to check that all parameters for the templates are given and of the right type instead of getting runtime errors because some mapping or context-object were of the wrong type. 我个人认为这是Play真正的强项之一,它允许编译器检查模板的所有参数是否均已指定并且类型正确,而不是因为某些映射或上下文对象类型错误而导致运行时错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM