javax约束的验证问题

qlckcl4x  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(300)

在SpringBoot应用程序中,我有一个实体,在其中放置了一些注解验证。

@Max(value = 17)
private String currency;

@Max(value = 1)
private String freq;

@Max(value = 2)
private String compliance;

@Max(value = 1)
private String payment;

@Max(value = 1)
private String wallet;

@Max(value = 2)
private String cycle;

@Max(value = 24)
private String histoProfil;

@Max(value = 20)
private String idNo;

@Max(value = 2)
private String special;

这些文件的值

freq="M";
compliance="";
currency="";
payment="";
wallet="O";
cycle="19"
histoProfil="";
idNo="Staple Bill";
special="";

我犯了很多错误

for freq: must be lower than or equal to 1
for currency: must be lower than or equal to 17
for compliance: must be lower than or equal to 2
for payment: must be lower than or equal to 1
for wallet: must be lower than or equal to 1
for cycle: : must be lower than or equal to 2
for histoProfil: must be lower than or equal to 24
for idNo: must be lower than or equal to 20
for special: must be lower than or equal to 2

freq只有一个字符,为什么我会收到这个消息?货币的空值低于17。。
我不明白为什么会发生这种错误。

0tdrvxhp

0tdrvxhp1#

@max注解是对以下类型的验证:bigdecimal、biginteger、byte、short、int、long以及它们各自的 Package 器。
https://docs.oracle.com/javaee/6/api/javax/validation/constraints/max.html
如果要验证字符串长度,请使用不同的注解@length(min,max)。

相关问题