Play 프레임 워크 템플릿의 내부 컨트롤러를 가져 오는 방법은 무엇입니까?
-
21-12-2019 - |
문제
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 ())
그런 다음 I 패스 컨트롤러의 PageList에 직접 얻을 수 있습니다.
해결책
컨트롤러를 직접 전달하는 것은 아마도 나쁜 아이디어 일 것입니다. 컨트롤러가 원하는 데이터 (PageList)를 나타내는 객체를 만드는 것이 좋습니다.
에 관계없이 "통과"가 무엇이든간에 컨트롤러 작업이며 이러한 모든 것들이 매개 변수라는 것을 기억하십시오.컨트롤러를 실제로 원한다면 페이지를 만드는 컨트롤러에서 this 키워드를 사용하십시오.
views.html.index.myPage(this, otherParam, ...)
. 제휴하지 않습니다 StackOverflow