[英]Scala parameter to Java (Play Framework)
Is there a way to pass the value from a Scala parameter to Java on the view using the Play Framework? 是否可以使用Play框架将值从Scala参数传递到视图上的Java?
Something like: 就像是:
<strong>Title: </strong> @addtitle
<a href="@routes.Application.shopping()" value="Add to Cart"
class="btn btn-primary btn-xs">@Messages("playauthenticate.results.shopping")
</a>
But I wanna put the @addtitle
as a parameter to the @routes.Application.shopping(@addtitle)
但是我
@addtitle
作为@routes.Application.shopping(@addtitle)
的参数
I'm using Play Framework 2.2.0. 我正在使用Play Framework 2.2.0。
Yes there is. 就在这里。
Let's say your Application
controller in the controllers
package had a function with this signature: 假设您在
controllers
软件包中的Application
控制器具有一个带有此签名的函数:
public static Result index(String name) { ... }
or (in Scala) 或(在Scala中)
def index(name: String) = Action { ... }
And you wanted the reverse router to produce the URL to this controller function from within the view: 并且您希望反向路由器从视图中生成指向此控制器功能的URL:
@routes.Application.shopping(addtitle)
Notice how we don't need the @
symbol within the arguments of the function. 注意,在函数的参数中我们如何不需要
@
符号。 It's already understood by the template compiler that it's reading scala, and not raw text. 模板编译器已经知道它正在读取scala,而不是原始文本。 This is of course, not limited to the reverse router, but any function.
当然,这不限于反向路由器,而是任何功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.