在模板中播放2.0 Framework外部模型 [英] Play 2.0 Framework external Model in Template

查看:52
本文介绍了在模板中播放2.0 Framework外部模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Play 2.0中,可以在模板中使用外部模型对象吗?

Is it possible in Play 2.0, to make use of external model objects in a template?

我可以从Controller类中的另一个jar中引用模型对象.我不知道如何在Play 2.0模板文件中引用外部模型对象.

I can reference model objects from another jar in a Controller class. I don't know how to reference external model objects inside the Play 2.0 template files.

推荐答案

没问题. 首先,通过将jar添加到lib目录或通过projects/Build.scala中的托管依赖项",将类添加到类路径中. 在模板视图文件中声明模型类时,请确保具有完全限定的名称. 在模板内部,您可以引用任何公共方法或成员.

No problem. First, add the class to your classpath, either by adding the jar to the lib dir or through the "managed dependencies" in the projects/Build.scala. Make sure to have fully qualified name when declaring your model class in the template view file. Inside the template, you can reference any public method or member.

@(varName : fully.qualified.name.MyClass)
<h1>@varName.myMember</h1>
<h1>@varName.myMethod</h1>

这篇关于在模板中播放2.0 Framework外部模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆