@NotNull和@NotEmpty和@NotBlank区别
验证框中@NotEmpty、@NotBlank、@NotNull很容易混淆,本文主要介绍一下各自的不同。
1.@NotNull:不能为null,但可以为empty。
2.@NotEmpty:不能为null,而且长度必须大于0
3.@NotBlank:只能作用在String上,不能为null,而且调用trim()后,长度必须大于0
例:
1.String name = null; @NotNull: false @NotEmpty:false @NotBlank:false 2.String name = ""; @NotNull:true @NotEmpty: false @NotBlank: false 3.String name = " "; @NotNull: true @NotEmpty: true @NotBlank: false 4.String name = "Great answer!"; @NotNull: true @NotEmpty:true @NotBlank:true
部分内容转载于 http://www.aichengxu.com/view/83440
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。