我在resources.groovy中定义了Spring bean.我可以在控制器中访问它们.我在视图中也有一些没有控制器的GSP.我想知道如何像在JSF中的EL表达式一样访问GSP中的bean?
例如,给定一个这样的域类:
class TestBean {
def name = "hello"
}
Run Code Online (Sandbox Code Playgroud)
在spring/resources.groovy:
test(mydomain.TestBean) { bean -> bean.scope = 'session' }
Run Code Online (Sandbox Code Playgroud)
在UrlMapping.groovy中:
'/test'(view:'/test')
Run Code Online (Sandbox Code Playgroud)
然后,在views/test.gsp中:
${test.name}
Run Code Online (Sandbox Code Playgroud)
但是上面的代码会引发异常,因为$ {test}为null.那么,如何在没有控制器的情况下在GSP中访问TestBean?
我正在使用Grails 2.2.谢谢!