PlayFramework2链接

时间:2012-06-16 20:39:13

标签: playframework-2.0

我可以通过以下方式创建html链接:

<a href="/about">About Us</a>

这将遵循/about的路由。但是在接下来的几页(我知道它是早期版本的Play,但我找不到2.0.1的任何信息):

http://www.playframework.org/documentation/1.1/tags

playframework how to call method from html in href that takes one parameter?

链接是从路由文件中获取的。我将以上链接的路由定义为:

GET /about controllers.Application.about()

在PlayFramework2中,如何通过传入控制器和函数名称以编程方式获取路由?

1 个答案:

答案 0 :(得分:7)

在模板中使用它:

<a href="@routes.Controller.method("param-value")">Link</a>

在你的情况下:

<a href="@routes.Application.about()">Link</a>

你也可以在控制器中使用类似语法的路由器:

public static Result redirectSomwhere(){
    return redirect(routes.Application.about());
}
相关问题