class DemoController {
static allowedMethods = [updatePerson: 'PUT']
def generateReport(int size) {
if(hasErrors()) {
errors.allErrors.each {
println it
}
}
}
def updatePerson(SomeDomainClass sdc) {
// if params.id is found then a call
// will have been made to SomeDomainClass.get(params.id)
// to retrieve the instance from the database.
// if no matching instance is found then
// sdc will be null and the controller
// will not have errors. If params.id
// is found and an exception occurs while
// trying to retrieve the instance then
// sdc will be null and an error will
// be added to the controller
if(sdc == null && hasErrors()) {
errors.allErrors.each {
println it
}
}
}
}
errors
用途
Spring Errors 接口的一个实例,其中包含与此控制器关联的错误。