playframework如何从带有一个参数的href中的html调用方法? [英] playframework how to call method from html in href that takes one parameter?

查看:98
本文介绍了playframework如何从带有一个参数的href中的html调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下路线

GET {company}.dev.alvazan.com/test  Web.test 
GET {company}.dev.alvazan.com/samplepage  Web.samplePage

我可以转到xxxx.dev.alvazan.com/test,直到我像这样添加对samplePage.html的引用....

I can go to xxxx.dev.alvazan.com/test just fine UNTIL I add a reference to samplePage.html like so....

<a href="@{Web.samplePage()}">TRY ME</a>

当然,这是因为该方法实际上是Web.samplePage(String company),以便用户可以直接转到该网页...但是我尝试更改为其中一种方法,但也不起作用. ..

and of course that is because the method is really Web.samplePage(String company) so that a user can go directly to that web page...but I try changing to one of theses and it doesn't work either...

<a href="@{Web.samplePage('${company}')}">TRY ME</a> 
<a href="@{Web.samplePage(${company})}">TRY ME</a>

如何确保html上方的href中的Web.samplePage是正确的?

How does one make sure the Web.samplePage is correct in the href above in the html???

谢谢, 院长

推荐答案

因为您已经指定了@符号,所以您无需再使用$符号,因为groovy编译器此时需要代码.因此,假设company已从控制器传递到视图中,那么您应该能够...

Because you have already specified the @ symbol, you don't need to then use the $ symbol, as the groovy compiler is at that point expecting code. So, assuming company has been passed into the view from the controller, you should be able to do...

<a href="@{Web.samplePage(company)}">TRY ME</a>

这篇关于playframework如何从带有一个参数的href中的html调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆