如何在Play framework 2.0模板中插入控制器操作的链接 [英] How to insert link to controller action in Play framework 2.0 template
本文介绍了如何在Play framework 2.0模板中插入控制器操作的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个动作 Application.show(tag:String)
,并且还有相应的路由条目,我该如何将此动作的链接插入模板没有手工制作网址?
If I have an action Application.show(tag: String)
, and also have a corresponding routing entry, how can I insert a link to this action to a template without crafting the url manually?
我想做一些像 magiclink(Application.show(tag))
。
推荐答案
语法:
<a href='@routes.Application.show("some")'>My link with some string</a>
通过类比,您还可以在控制器中生成网址。即。在某些操作后重定向:
By analogy you can also generate urls in your controllers. ie. for redirecting after some action:
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"));
}
这篇关于如何在Play framework 2.0模板中插入控制器操作的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文