Grails 对 int 列的约束抛出 java.lang.IllegalArgumentException
我对两个整数 Score 和 numOfQuestions 有以下约束。
score blank:false, min:1, nullable:false, notEqual:null
numOfQuestions blank:false, min:1, nullable:false, notEqual:null
可以看出,我希望这些字段大于 0 并且不应该为空或空白,但无论我做什么,而不是显示一条友好的消息,如“属性不能为空”,我的屏幕上会充满长异常。 .. 还有其他方法可以验证非空白输入的整数吗?
Failed to convert property value of type java.lang.String to required type int for property numOfQuestions; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [int] for property numOfQuestions: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type [null]
我看过这个 http://jira.grails.org/browse/GRAILS-4603但没有多大帮助
I have following constraints on two integers, score and numOfQuestions.
score blank:false, min:1, nullable:false, notEqual:null
numOfQuestions blank:false, min:1, nullable:false, notEqual:null
As it can be seen I want these fields to be greater then 0 and should not be null or blank but regardless of what I do, rather then showing a friendly message like "property can not be blank" my screen gets filled with long exception...
Is there any other way to validate integers for non blank inputs?
Failed to convert property value of type java.lang.String to required type int for property numOfQuestions; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [int] for property numOfQuestions: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type [null]
I have seen this http://jira.grails.org/browse/GRAILS-4603 but didn't help much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以将上面的约束替换为:
因为
min:1
意味着 not-null。约束blank: false
只能应用于String
属性,因此您将此约束与数字属性一起使用可能会导致您看到的异常。I think you can replace the constraints above with just:
Because
min:1
implies not-null. The constraintblank: false
can only be applied toString
properties, so you're use of this constraint with a numeric property is probably responsible for the exception you're seeing.