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.
支持任何类型。
@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.错误。
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: JAVA对象属性复制