我的 Controller 是这样的:
class UserController{
def register= {UserCommand command ->
println params
println command.dump()
// do something ..........
}
}
class UserCommand {
String username
static constraints = {
username nullable: false
}
}
我的gsp文件有一个表单,其输入(文本)名为:“command.username”,提交表单后,我可以看到参数打印出来,但我的命令对象是空的,我认为命令对象是假设的当您传递参数数据时自动将其与参数数据绑定(bind),我错过了什么吗?
谢谢
最佳答案
绑定(bind)到命令对象会将参数中的键与命令对象上的属性进行匹配,这与从参数到域对象的绑定(bind)的工作方式相同。表单中的属性应命名为username
,而不是command.username
。 command.username
将尝试绑定(bind)到 UserCommand
上 command
对象的 username
属性。
关于grails - 无法将 GSP 参数绑定(bind)到 Controller 中的命令对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677876/