ron*_*ron 13 templates hyperlink playframework-2.0
如果我有一个操作Application.show(tag: String)
,并且还有相应的路由条目,如何在不手动创建URL的情况下将此操作的链接插入模板?
我想做点什么magiclink(Application.show("tag"))
.
bie*_*ior 18
句法:
<a href='@routes.Application.show("some")'>My link with some string</a>
Run Code Online (Sandbox Code Playgroud)
通过类比,您还可以在控制器中生成URL.即.一些动作后重定向:
public static Result justRedirect(){
// use as String
String urlOfShow = routes.Application.index().toString().
// or pass as a redirect() arg
return redirect(routes.Application.show("some"));
}
Run Code Online (Sandbox Code Playgroud)
将routes
文件中的 URL 放入html 的格式如下:
@routes.NameOfYourClass.nameOfyourMethod()
Run Code Online (Sandbox Code Playgroud)
因此,如果您的routes
文件中有:
GET /products controllers.Products.index()
Run Code Online (Sandbox Code Playgroud)
你的Products
班级看起来像这样:
@routes.NameOfYourClass.nameOfyourMethod()
Run Code Online (Sandbox Code Playgroud)
你<a>
应该是这样的:
<a href="@routes.Products.index()">Products</a>
Run Code Online (Sandbox Code Playgroud)
另外:如果你的方法可以接受参数,那么你当然可以把它们放入你的方法是这样的圆括号之间: index("Hi")
。
我希望这个答案更容易理解。
归档时间: |
|
查看次数: |
11442 次 |
最近记录: |