我很难搞清楚这个简单代码中的错误:
这是我更改密码的命令:
package myapp.commands
import org.springframework.web.context.request.RequestContextHolder as RCH
import myapp.User
class PasswordCommand {
String currentPassword
String password
String passwordConfirm
private u
User getUser() {
def id = RCH.requestAttributes.session?.user?.id
if (!u && id) {
u = User.get(id)
}
return u
}
static constraints = {
currentPassword blank: false, validator: { val, cmd ->
if (cmd.user && cmd.user.password != val)
return "user.password.invalid"
}
...
}
在相应的控制器中,我使用此操作:
def doPassword = { PasswordCommand cmd ->
if (!cmd.hasErrors()) {
User user = cmd.getUser()
...
不幸的是,当我尝试更改密码时收到错误500:
URI: /Myapp/user/doPassword
Class: java.lang.NoSuchMethodError
Message: PasswordCommand.validate()Z
发生什么事了?!
答案 0 :(得分:1)
添加@Validateable
注释:
import grails.validation.Validateable
...
@Validateable
class PasswordCommand {
...
}