grails:最小约束和BigDecimal类型的属性(类型不匹配?)

Ale*_*exx 1 grails constraints min

在grails类中,我指定了

BigDecimal  amount
Run Code Online (Sandbox Code Playgroud)

代表交易中的金额.

然后,在约束部分,我指定:

amount      ( nullable:false, min : 100)
Run Code Online (Sandbox Code Playgroud)

表明接受的最低金额是一美元.这编译得很好,但运行时抛出了类型不兼容错误:

2011-10-26 15:17:06,116 [main] ERROR validation.ConstrainedProperty  - Exception thrown applying constraint [min] to class [class com.mycorp.mypkg.MyProprietaryDefinition] for value [100]: Parameter for constraint [min] of property [amount] of class [class  com.mycorp.mypkg.MyProprietaryDefinition] must be the same type as property: [java.math.BigDecimal]
Run Code Online (Sandbox Code Playgroud)

我是否安全地假设我无法在BigDecimal属性上指定最小值?

谢谢!

阿里克斯

jam*_*man 7

Grails希望minmax值与关联属性的数据类型相同,而scale值始终要求为Integer.转换为BigDecimal或将.0添加到值的末尾可以解决问题.

amount(nullable: false, min: 100.0, max: 9999.99, scale: 2)
Run Code Online (Sandbox Code Playgroud)

我最近提交了有关此问题的IntelliJ IDEA错误报告IDEA-75471.如果最小值最大值不是整数且标度值与属性的数据类型不同,则IDEA 10.5.2会错误地标记检查警告.使用可以忽略警告//noinspection GroovyAssignabilityCheck.