@size(max = value) 和 @min(value) 和 @max(value) 的区别 [英] Difference between @size(max = value ) and @min(value) and @max(value)

查看:79
本文介绍了@size(max = value) 和 @min(value) 和 @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>(代表数字)、intshortbyte 等以及它们各自的原始包装器.

@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 支持 StringCollectionMaparrays> 而 @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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆