播放反向路由-获取绝对网址 [英] Play reverse routing - getting absolute url

查看:71
本文介绍了播放反向路由-获取绝对网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下操作时,如何在play 2.2 scala中获取绝对URL:

How can I get the absolute URL in play 2.2 scala when doing the following:

val promoLink = routes.Promotions.promotionsCategory(DOCID, slug)


//routes file

GET /promotions/:DOCID:/slug     controllers.Promotions.promoCat(DOCID, slug)

就目前情况而言,我在期待一个字符串时得到了一个发现:play.api.mvc.Call"类型不匹配

As it stands I get a "found : play.api.mvc.Call" type mismatch on expecting a string

谢谢

推荐答案

我想您的promoLink应该是包含网址的String?您的问题听起来有点不清楚.

I suppose your promoLink should be a String containing an URL? Your question sounds a bit unclear.

如果是这样,那么您可能需要此:

If so then you probably need this:

val promoLink = routes.Promotions.promotionsCategory(DOCID, slug).absoluteURL(false)(request)

.absoluteURL(false)中的

false代表isSecure参数,它将为您提供httphttps网址.

false in the .absoluteURL(false) stands for the isSecure parameter which will give you http or https url.

如果您在范围中有隐式请求,则可以省略最后一个(request)部分

If you have an implicit request in scope you may omit the last (request) part

这篇关于播放反向路由-获取绝对网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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