命令对象验证失败,getter与属性无关(Grails 3.1,3.2)

时间:2017-11-13 22:00:36

标签: grails

我有一个像这样的控制器:

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']

0 个答案:

没有答案