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.
支持任何类型。
@NotEmptyAsserts 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.错误。