我使用playframework2.2:

我的模板是:

@(topiclink:String, head: String, rate: Int, topicid:Int, summary: String, pic_url:String)
@if(topiclink=="Shoplist"){
<a class="list-group-item" href="@routes.ShoplistController.pagelist(topicid.toString())">
}else {
 <a class="list-group-item" href="@routes.PageController.pagelist(topicid.toString())"> 

}</a>
.

我想写更多OOP,我的意思是我想使用以下参数:

@(topiclink:Controller, head: String, rate: Int, topicid:Int, summary: String, pic_url:String)
.

然后可以直接@ topiclink.pagelist(topicId.tostring())

然后我可以直接进入对应控制器捕手。

有帮助吗?

解决方案

直接传递控制器可能是一个坏主意 - 考虑控制控制器创建代表您想要的数据(宠物师)的对象。

无论如何,无论你“通过”,它是控制器作业“通过它” - 记住所有这些东西都是参数。如果您真的想要控制器,那么在创建页面的控制器中使用这个关键字:

views.html.index.myPage(this, otherParam, ...)
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top