我正在尝试使用反向路由来访问静态资源:
@routes.Assets.at("path", "file")
但是我也想将文件定义为动态部分,例如:
@for(c <- models.WebContent.find.all) {
<img src="@routes.Assets.at("/contentfiles/useruploads", "@c.picture1")">
}
上面的语句会生成 HTML 代码:
<img src="/contentfiles/userupload/@c.picture1">
您可以看到动态部分 @c.picture1 不被解释为动态文件名,而是被解析为原始文本,导致链接损坏。我期望的是两个动态部分都被解释为动态结果,例如:
<img src="/contentfiles/userupload/1776446515.jpg">
如何定义它以便两个动态语句都被解析为动态? PS:我尝试将其转义为 @@c.picture 或 $@c.picture,但没有成功
谢谢
最佳答案
当使用变量作为函数参数时,请使用它,不带 @
字符,也不用引号括起来,否则,您可以将其用作...字符串
<img src="@routes.Assets.at("/contentfiles/useruploads", c.picture1)">
与条件相同:
Use:
@if(foo==bar){...}
NOT
@if(@foo==@bar){...}
关于java - Assets 反向路由中的动态文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26069616/