@size(max = value) 和 @min(value) 和 @max(value) 的区别 [英] Difference between @size(max = value ) and @min(value) and @max(value)
问题描述
我想做一些域验证.在我的对象中,我有一个整数.
I want to do some domain validation. In my object I have one integer.
现在我的问题是:如果我写
Now my question is: if I write
@Min(SEQ_MIN_VALUE)
@Max(SEQ_MAX_VALUE)
private Integer sequence;
和
@Size(min = 1, max = NAME_MAX_LENGTH)
private Integer sequence;
如果是整数,哪个适合域验证?
谁能解释一下它们之间有什么区别?
If it's an integer which one is proper for domain validation?
Can anybody explain me what is the difference between them?
谢谢.
推荐答案
@Min
和 @Max
用于验证可以是 String<的数字字段/code>(代表数字)、
int
、short
、byte
等以及它们各自的原始包装器.
@Min
and @Max
are used for validating numeric fields which could be String
(representing number), int
, short
, byte
etc and their respective primitive wrappers.
@Size
用于检查字段的长度限制.
@Size
is used to check the length constraints on the fields.
根据文档 @Size
支持 String
、Collection
、Map
和 arrays
> 而 @Min
和 @Max
支持原语及其包装器.请参阅文档.
As per documentation @Size
supports String
, Collection
, Map
and arrays
while @Min
and @Max
supports primitives and their wrappers. See the documentation.
这篇关于@size(max = value) 和 @min(value) 和 @max(value) 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!