【问题标题】:How to map all values of an enum to constant expression?如何将枚举的所有值映射到常量表达式?
【发布时间】:2014-10-31 11:48:20
【问题描述】:

我想将枚举的所有可用值添加到hibernate validation 消息中。但我不能,因为它需要一个常量表达式。

@NotNull(message = "Allowed values: " + MyEnum.values());

结果错误:

The value for annotation attribute NotNull.message must be a constant expression

如何做到这一点?

【问题讨论】:

标签: java hibernate enums hibernate-validator


【解决方案1】:

我不认为这是可以做到的。另见Use Enum type as a value parameter for @RolesAllowed-Annotation

基本上需要将编译时常量表达式传递给message。另见JSL section

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 2011-04-08
    • 1970-01-01
    • 2019-04-09
    • 2019-08-14
    相关资源
    最近更新 更多