【问题标题】:grails - min / max constraints fail for float?grails - 最小/最大约束因浮动而失败?
【发布时间】:2015-11-12 14:47:11
【问题描述】:

我有这门课:

class SomeClass {

    float percent

    static constraints = {
        percent(min:1.0F, max:100.0F)
    }
}

当我启动应用程序时出现错误:

Parameter for constraint [min] of property [percent] of class [class SomeClass] must be the same type as property: [float]

这是一个错误还是我做错了什么?

【问题讨论】:

    标签: grails constraints grails-orm


    【解决方案1】:

    我认为你应该使用小的f 而不是F

    static constraints = {
        percent(min:1.0f, max:100.0f)
    }
    

    尝试将percent的类型改为Float,那么1.0F应该是有效的

    【讨论】:

    • 这是我首先尝试的。这有同样的结果。我在文档中找到了一个带有大字母 F 的示例 - 这就是我这样写的原因
    • 尝试将percent的类型改为Float,那么1.0F应该是有效的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-27
    • 1970-01-01
    • 2011-05-04
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多