@Max 不接受长包装类型的 10 位数字
@Max does not accept 10 digits on long wrapper type
作为实体定义的一部分,@Max(javax.validation.constraints.Max) 不会采用上限值来验证 10 位整数
@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
columnDefinition = "INT(10) NOT NULL")
private Integer someColumn;
Eclipse 在消息 The value for annotation attribute Max.value must be a constant expression
.
的第二行浮动一个红色标记
我翻找了 MAX_VALUE
for Integer
却发现它也是 2147483647
,也是 10 位数字。
注意: hibernate-core:5.0.12
, validation-api:2.0.0.CR3
我修改了类型为long wrapper
@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
columnDefinition = "INT(10) NOT NULL")
private Long someColumn;
但是,错误依旧是固执。
@Max
的参数定义为 long
。例如,将其设置为 42
意味着传递 int
值 42
,它会转换为 long
值 42L
,然后进行设置。标准操作程序,真的。 @Max
这里没有什么特别的。
当您传递 9999999999
时,它会尝试将其解释为 int
但失败了。 Eclipse 正在警告您这一点,只是可能不是很清楚。要传入 9999999999
,您需要将其作为 long
,这意味着将约束指定为 @Max(9999999999L)
。
作为实体定义的一部分,@Max(javax.validation.constraints.Max) 不会采用上限值来验证 10 位整数
@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
columnDefinition = "INT(10) NOT NULL")
private Integer someColumn;
Eclipse 在消息 The value for annotation attribute Max.value must be a constant expression
.
我翻找了 MAX_VALUE
for Integer
却发现它也是 2147483647
,也是 10 位数字。
注意: hibernate-core:5.0.12
, validation-api:2.0.0.CR3
我修改了类型为long wrapper
@Min(0)
@Max(9999999999)
@Column(name = "some_column", nullable = false,
columnDefinition = "INT(10) NOT NULL")
private Long someColumn;
但是,错误依旧是固执。
@Max
的参数定义为 long
。例如,将其设置为 42
意味着传递 int
值 42
,它会转换为 long
值 42L
,然后进行设置。标准操作程序,真的。 @Max
这里没有什么特别的。
当您传递 9999999999
时,它会尝试将其解释为 int
但失败了。 Eclipse 正在警告您这一点,只是可能不是很清楚。要传入 9999999999
,您需要将其作为 long
,这意味着将约束指定为 @Max(9999999999L)
。