我有一个像这样的控制器:
class DemoController {
def index() {
DemoCommand cmd = new DemoCommand(demoAmount: 'foo')
render cmd.validate() ? "Validation successful" : "Validation failed, ${cmd.errors}"
}
}
class DemoCommand implements Validateable {
String demoAmount
static constraints = {
demoAmount nullable: false
}
Long getDemoAmountAsLong() {
demoAmount?.isNumber() ? new Long(demoAmount) : null
}
}
点击索引操作显示验证失败,说明demoAmountAsLong不能为空。在这个问题上,3.1.2(https://github.com/grails/grails-core/issues/9754)报告了一些错误,但看起来已经解决了。我已经在3.1.11和3.2.11中对此进行了测试,结果相同。我肯定错过了什么?我尝试过使用getter方法,或者在没有运气的情况下添加static transients = ['demoAmountAsLong']
。