在我的GSP文件中
<g:form controller="hello" action="createUser">
<g:select id="users" class="required" name="users" from="${hello.HelloController.userList()}" noSelection="['':'-Select user-']"/>
在我的HelloController中
class HelloController {
..
def users= []
...
def userList= {
return users;
}
我得到的错误
groovy.lang.MissingMethodException
Message
No signature of method: static hello.HelloController.userList() is applicable for argument types: () values
我尝试仅使用
from=${userList()}
并将userList更改为static。所有这些都会带来更多错误。这在我在新计算机上设置新环境时执行grails升级之前一直有效
最佳答案
您需要在此处更改几件事。
一种,定义 Controller Action 的首选方法是方法而不是闭包。
class HelloController {
def userList() {
return users
}
}
第二,您的 View 不应调用 Controller 方法。 Controller Action 应返回渲染 View 所需的模型。
class HelloController {
def list() {
return [userList: users]
}
}
然后,在您的 View 中(即
hello/list.gsp
),您可以访问userList
。
关于grails - 升级后出现Grails groovy.lang.MissingMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23688615/