按逻辑顺序执行JSR-303验证 [英] Doing JSR-303 validation in logical order
本文介绍了按逻辑顺序执行JSR-303验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的域模型类验证约束中有以下字段:
I have such field in my domain model class validation constraints:
@Column(nullable = false, name = "name")
@NotEmpty(groups = {Envelope.Insert.class, Envelope.Update.class})
@Size(min = 3, max = 32)
private String name;
当此字段为空(")或为null时,验证器会同时生成不能为空"和大小必须在...之间"错误消息.我理解这一点,但是当我向客户端显示此验证错误时,这似乎很奇怪(因为当某些内容为空/空时,它不能满足大小要求,这是不合逻辑的).
When this field is empty ("") or null, validator produces both "cannot be empty" and "size must be between..." error messages. I understand it, but when I show this validation error to the client, it seems quite odd (because when something is null / empty it cannot fulfill size requirement, it's not a logical).
有什么方法可以告诉Spring以正确的顺序进行验证吗?如果不是@NotEmpty
,则不要检查@Size
,并且在满足@NotEmpty
的情况下检查@Size
.
Is there some way how to tell Spring to do validation in proper order? If is not @NotEmpty
then do not check @Size
, and when @NotEmpty
is fulfilled check @Size
.
推荐答案
查看全文