[英]What does element size represents?
我將注解@Size
視為Spring控制器中的限制。 我一直在尋找尺寸的確切解釋,結果發現:
將評估字段或屬性的大小,並且必須匹配指定的邊界。 如果字段或屬性是字符串,則將評估字符串的大小。 如果字段或屬性是Collection,則將評估Collection的大小。 如果字段或屬性是Map,則將評估Map的大小。 如果字段或屬性是數組,則將評估數組的大小。 使用可選的max或min元素之一來指定邊界。
但是,我不清楚如何計算String的大小。 是其中的字符數嗎? 它是字節數嗎? 有人知道嗎
您沒有說在哪里找到該解釋,但是javax.validation.constraints.Size
Javadoc說
The annotated element size must be between the specified boundaries (included).
Supported types are:
CharSequence (length of character sequence is evaluated)
Collection (collection size is evaluated)
Map (map size is evaluated)
Array (array length is evaluated)
null elements are considered valid.
請注意, String
是一個CharSequence
它是字符串中的字符數。
@Size
Javadoc說:
The annotated element size must be between the specified boundaries (included).
Supported types are:
CharSequence (length of character sequence is evaluated)
Collection (collection size is evaluated)
Map (map size is evaluated)
Array (array length is evaluated)
null elements are considered valid.
String
是CharSequence
,如果我們在此接口中查看length()
方法的注釋,則會看到:
長度是序列中16位字符的數量。
有關@Size
和其他驗證程序的更多詳細信息,請參見http://beanvalidation.org/ 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.