我在返回 url 的域类中有静态方法。我需要动态构建该网址,但 g.link 不起作用。
static Map options() {
// ...
def url = g.link( controller: "Foo", action: "bar" )
// ...
}
我收到以下错误:
Apparent variable 'g' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance variable from a static context.
You misspelled a classname or statically imported field. Please check the spelling.
You attempted to use a method 'g' but left out brackets in a place not allowed by the grammar.
@ line 17, column 19.
def url = g.link( controller: "Foo", action: "bar" )
^
1 error
显然我的问题是我试图g
从静态上下文访问,那么我该如何解决这个问题?