Hibernate validator限制參數非空方法

Hibernate validator有下面三種註釋來限制輸入參數必須非空

@NotBlank

Validate that the annotated string is not null or empty. The difference to NotEmpty is that trailing whitespaces are getting ignored.

用於字符串,會忽略字符串尾部的空格

@NotNull

The annotated element must not be null. Accepts any type.

支持任何類型。

@NotEmpty

Asserts that the annotated string, collection, map or array is not null or empty.

用於字符串(不會忽略字符串尾部的空格),集合,map和array。


如何使用@NotBlank Long id,將會出現javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Long.錯誤。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章