I came across a groovy syntax that creates a link in gsp file like this:
class LoginTagLib {
def loginControl = {
out << """[${link(action:"login",controller:"user"){"Login"}}]"""
}}
I know that it will eventually turned into this in html:
<a href="/racetrack/user/login">Login</a>
However, there are 2 portion of the syntax that I don't understand:
I don't understand ${link(action:"login",controller:"user"){"Login"}}
:
$()
, which is used for string interpolation. link(action:"login",controller:"user")
too, just 2 arguments passed into link
{"Login"}
doing behind? I don't understand the """[ ]"""
that is used to enclose the whole thing, I tried to take away a pair of "
, but it wounldn't work anymore. So it proves to me it has it's significance.
Anybody help to shed some light?
Thanks
foo(arg1, arg2, ..., { ... })
to foo(arg1, arg2, ...) { ... }
. this is what happens here, the last argument of link()
is a closure that should evaluate to the textual representation of the link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.